在 Visual Basic 6 中使用 Adodb 记录集到 VB.net
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20736219/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Using Adodb recordset in visual basic 6 to VB.net
提问by Jeff
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
回答by Jeff
It's been awhile since I've used ADODB but I think this should work
自从我使用 ADODB 已经有一段时间了,但我认为这应该有效
Amount = rs.Fields.Item("Balance").Value

