VB 中的datagrid控件
怎样用代码绑定datagrid控件我写的是PrivateSubCommand1_Click()DimcnAsNewADODB.Connectioncn.Connectio...
怎样用代码绑定datagrid控件
我写的是
Private Sub Command1_Click()
Dim cn As New ADODB.Connection
cn.ConnectionString = "DSN=depot;uid=dailongjian;pwd=19881127"
Dim rs As New ADODB.Recordset
cn.Open
Set rs = cn.Execute("select p.* from d,p where p.dno=d.dno and dl='" & Combo1.Text & "'")
Set DataGrid1.DataSource = rs
End Sub
但出现错误
Set DataGrid1.DataSource = rs这句上的错误 展开
我写的是
Private Sub Command1_Click()
Dim cn As New ADODB.Connection
cn.ConnectionString = "DSN=depot;uid=dailongjian;pwd=19881127"
Dim rs As New ADODB.Recordset
cn.Open
Set rs = cn.Execute("select p.* from d,p where p.dno=d.dno and dl='" & Combo1.Text & "'")
Set DataGrid1.DataSource = rs
End Sub
但出现错误
Set DataGrid1.DataSource = rs这句上的错误 展开
3个回答
展开全部
Private Sub Command1_Click()
Dim cn As New ADODB.Connection
cn.ConnectionString = "DSN=depot;uid=dailongjian;pwd=19881127"
Dim rs As New ADODB.Recordset
cn.Open
rs.CursorLocation = adUseClient
rs.open "select p.* from d,p where p.dno=d.dno and dl='" & Combo1.Text & "'",cn,1,3
Set DataGrid1.DataSource = rs
End Sub
Dim cn As New ADODB.Connection
cn.ConnectionString = "DSN=depot;uid=dailongjian;pwd=19881127"
Dim rs As New ADODB.Recordset
cn.Open
rs.CursorLocation = adUseClient
rs.open "select p.* from d,p where p.dno=d.dno and dl='" & Combo1.Text & "'",cn,1,3
Set DataGrid1.DataSource = rs
End Sub
展开全部
'Set rs = cn.Execute("select p.* from d,p where p.dno=d.dno and dl='" & Combo1.Text & "'")这句有问题,cn.Execute只是执行,不会查询,不返回记录集,这行代码改为rs.open "select p.* from d,p where p.dno=d.dno and dl='" & Combo1.Text & "'"
'部件->选中"Microsoft ADO Data Control 6.0"->添加控件Adodc1
'代码中master修改为你的数据库名称,F493修改为你的服务管理器名称
With Adodc1
.ConnectionString = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=master;Data Source=F493"
.RecordSource = "Select * From msreplication_options"
End With
Set DataGrid1.DataSource = Adodc1
'部件->选中"Microsoft ADO Data Control 6.0"->添加控件Adodc1
'代码中master修改为你的数据库名称,F493修改为你的服务管理器名称
With Adodc1
.ConnectionString = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=master;Data Source=F493"
.RecordSource = "Select * From msreplication_options"
End With
Set DataGrid1.DataSource = Adodc1
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Set DataGrid1.recordsoure = rs
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询