user2081574
user2081574

Reputation:

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

Upvotes: 0

Views: 18869

Answers (2)

Ray E
Ray E

Reputation: 154

It's that rs!Balance piece of code that's not right. Another way to do this:

    Dim Amount As Decimal = rs.Fields("Balance").Value

Upvotes: 0

Jeff
Jeff

Reputation: 918

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

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

Upvotes: 4

Related Questions