Search code examples
vb.netvisual-studiovb6ado.net

Using Adodb recordset in visual basic 6 to VB.net


This codes below are working with visual basic 6.0 and I wanted this code to be used in vb.net and I think there are errors when I typed it on vb.net(Visual Studio 2013)

the name of my MS access database is "mySavings.accdb"

the table name is "Balance" with a field named "Balance"

I already added the reference: Microsoft ActiveX Data Objects 6.0 Library Microsoft ActiveX Data Objects Recordset 6.0 Library Thank you in advance and here's my code in VB6

Public con As New ADODB.Connection
Public rs As New ADODB.Recordset    
    Dim Amount as String
Private Sub Form_Load()
    con.Open ("Provider=Microsoft.ACE.OLEDB.12.0; Data Source = C:\Users\MyPc\Documents\Visual Studio 2013\Projects\mySavings.accdb")

    rs.Open ("Select * from Savings"), con, 3, 2
    Amount = rs!Balance
    msgbox("You're current balance is " & Amount)
End Sub

Solution

  • It's been awhile since I've used ADODB but I think this should work

    Amount = rs.Fields.Item("Balance").Value