如何用vb读取access表中数据,并赋值给另一变量? 急! 10
例如,access中有一表:书名价格数量aaa102bbb155...欲把价格字段各值赋给变量Q.用vb语言如何实现conn.open"provider=Microsof...
例如,access中有一表:
书名 价格 数量
aaa 10 2
bbb 15 5...
欲把价格字段各值赋给变量Q.用vb语言如何实现
conn.open "provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & App.Path & "\abc.mdb"
报错,说要求有对象的提示? 展开
书名 价格 数量
aaa 10 2
bbb 15 5...
欲把价格字段各值赋给变量Q.用vb语言如何实现
conn.open "provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & App.Path & "\abc.mdb"
报错,说要求有对象的提示? 展开
展开全部
Private Sub Command1_Click()
Dim conn As Object, rs As Object, q As Currency
Set conn = CreateObject("adodb.connection")
Set rs = CreateObject("adodb.recordset")
conn.open "provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & App.Path & "\数据库名.mdb"
rs.open "select 价格 from 表名 where 书名='aaa'", conn, 1, 1
If Not rs.EOF Then q = rs(0)
rs.Close
conn.Close
Set rs = Nothing
Set conn = Nothing
MsgBox "书名为《aaa》的书价格为" & q & "元"
End Sub
Dim conn As Object, rs As Object, q As Currency
Set conn = CreateObject("adodb.connection")
Set rs = CreateObject("adodb.recordset")
conn.open "provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & App.Path & "\数据库名.mdb"
rs.open "select 价格 from 表名 where 书名='aaa'", conn, 1, 1
If Not rs.EOF Then q = rs(0)
rs.Close
conn.Close
Set rs = Nothing
Set conn = Nothing
MsgBox "书名为《aaa》的书价格为" & q & "元"
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询