简体   繁体   中英

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

自从我使用 ADODB 已经有一段时间了,但我认为这应该有效

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM