vb datagrid显示问题(ado对象连接数据库)
窗体只设置一个datagrid控件用来显示数据,代码如下:PrivateSubForm_Load()DimcnAsADODB.ConnectionDimrsAsADODB...
窗体只设置一个datagrid控件用来显示数据,代码如下:
Private Sub Form_Load()
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim cmd As ADODB.Command
Dim cnstr As String
Set cn = New ADODB.Connection
cn.CursorLocation = adUseClient
cnstr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\Program Files\VB98\vb\mydb.mdb;Persist Security Info=False"
cn.ConnectionString = cnstr
cn.Open
Set rs = New ADODB.Recordset
Set rs.ActiveConnection = cn
rs.Open "select * from 表1", cn, adOpenStatic, adLockOptimistic
Set DataGrid1.DataSource = rs
'Set cmd = New ADODB.Command
'Set cmd.ActiveConnection = cn
End Sub
我的问题是:
这样设置后,datagrid并没有显示数据,请高手指教
怎样才能显示数据
送上全部大洋,谢谢各位 展开
Private Sub Form_Load()
Dim cn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim cmd As ADODB.Command
Dim cnstr As String
Set cn = New ADODB.Connection
cn.CursorLocation = adUseClient
cnstr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\Program Files\VB98\vb\mydb.mdb;Persist Security Info=False"
cn.ConnectionString = cnstr
cn.Open
Set rs = New ADODB.Recordset
Set rs.ActiveConnection = cn
rs.Open "select * from 表1", cn, adOpenStatic, adLockOptimistic
Set DataGrid1.DataSource = rs
'Set cmd = New ADODB.Command
'Set cmd.ActiveConnection = cn
End Sub
我的问题是:
这样设置后,datagrid并没有显示数据,请高手指教
怎样才能显示数据
送上全部大洋,谢谢各位 展开
2个回答
展开全部
datagrid的属性里有一个属性Datasource的属性,需要连接到一个Adodc控件上。你连接了吗?不连接无法显示数据
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Private Sub Form_Load()
Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim sql As String
Dim cnstr As String
cn.CursorLocation = adUseClient
cnstr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\Program Files\VB98\vb\mydb.mdb;Persist Security Info=False"
cn.ConnectionString = cnstr
cn.Open cnstr
sql = "select * from 表1"
rs.Open sql, cn, adOpenStatic, adLockOptimistic 'adOpenStatic或许用adOpenDynamic
Set DataGrid1.DataSource = rs
End Sub
Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim sql As String
Dim cnstr As String
cn.CursorLocation = adUseClient
cnstr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\Program Files\VB98\vb\mydb.mdb;Persist Security Info=False"
cn.ConnectionString = cnstr
cn.Open cnstr
sql = "select * from 表1"
rs.Open sql, cn, adOpenStatic, adLockOptimistic 'adOpenStatic或许用adOpenDynamic
Set DataGrid1.DataSource = rs
End Sub
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询