简体   繁体   English

在 Visual Basic 6 中使用 Adodb 记录集到 VB.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)下面的代码适用于visual basic 6.0,我希望在vb.net中使用此代码,我认为在vb.net(Visual Studio 2013)上键入时出现错误

the name of my MS access database is "mySavings.accdb"我的 MS Access 数据库的名称是“mySavings.accdb”

the table name is "Balance" with a field named "Balance"表名是“Balance”,有一个名为“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我已经添加了参考:Microsoft ActiveX Data Objects 6.0 Library Microsoft ActiveX Data Objects Recordset 6.0 Library 提前谢谢你,这是我在 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.是 rs!Balance 代码不对。 Another way to do this:另一种方法来做到这一点:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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