VB6.0用DataGrid1怎么显示sql数据库 30
PublicmyconAsNewADODB.ConnectionPublicmyrsAsNewADODB.RecordsetPrivateSubForm_Load()my...
Public mycon As New ADODB.Connection
Public myrs As New ADODB.Recordset
Private Sub Form_Load()
mycon.ConnectionString = "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;password=123456Q;Initial Catalog=Library;Data Source=127.0.0.1"
mycon.Open
Set Adodc1.Recordset = mycon.Execute("select * from book")
Set DataGrid1.DataSource = myrs '绑定数据库
End Sub 展开
Public myrs As New ADODB.Recordset
Private Sub Form_Load()
mycon.ConnectionString = "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;password=123456Q;Initial Catalog=Library;Data Source=127.0.0.1"
mycon.Open
Set Adodc1.Recordset = mycon.Execute("select * from book")
Set DataGrid1.DataSource = myrs '绑定数据库
End Sub 展开
2个回答
展开全部
Set myrs = mycon.Execute("select * from book")
改为
Set Adodc1.Recordset = mycon.Execute("select * from book")
或者
Adodc1.Recordset.Open "select * from book", mycon, 1, 1
改为
Set Adodc1.Recordset = mycon.Execute("select * from book")
或者
Adodc1.Recordset.Open "select * from book", mycon, 1, 1
追问
Set DataGrid1.DataSource = Adodc1 '提示错误:行集合不能作为标签
于是我改成了 Set DataGrid1.DataSource = myrs ‘但是还是不行
追答
Private Sub Form_Load()
Adodc1.ConnectionString = "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;password=123456Q;Initial Catalog=Library;Data Source=127.0.0.1"
Adodc1.RecordSource = "select * from book"
Set DataGrid1.DataSource = Adodc1
End Sub
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Set Adodc1.Recordset = mycon.Execute("select * from book")
Set DataGrid1.DataSource = Adodc1.Recordset '绑定数据库
adodb和adodc一般来讲只用一个就可以了,混用也是可以,但可能会造成不必要的麻烦。
Set DataGrid1.DataSource = Adodc1.Recordset '绑定数据库
adodb和adodc一般来讲只用一个就可以了,混用也是可以,但可能会造成不必要的麻烦。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询