VB的ADO于True DBGrid
在运行True DBGrid自带的ADO例子是出现错误:Error opening RecorsSet! -2147418113必须加载一个.dll 不知我应当加载那个.dll。重装一次还是那样,随这个例子的Readme内容如下:
This sample shows how you can populate the grid in Unbound extended mode from an ADO recordset.
Note: Users of OLEDB version should use the DataMode 0 - Bound and the DataSource property of the grid. For example:
Dim cn As New ADODB.Connection
Dim rs As New ADODB.RecordSet
Private Sub Command1_Click()
Dim strConnect As String
' Open a database and working recordset
strConnect = "driver={Microsoft Access Driver (*.mdb)};DBQ=" & txtDBName.Text
cn.Open strConnect
rs.CursorType = adOpenKeyset
rs.LockType = adLockOptimistic
' Use client cursor to enable AbsolutePosition property.
rs.CursorLocation = adUseClient
rs.Open txtSQL.Text, cn
Set TDBGrid1.DataSource = rs
TDBGrid1.ReBind
End Sub
我的例子如下,窗体上有两个Command和一个TDBGrid。按一键TDBGrid没有任何反映,按二键表报出现但里面是空的。
Dim myCon As ADODB.Connection
Dim myRS As ADODB.Recordset
Private Sub Command1_Click(Index As Integer)
Select Case Index
Case 0
Set myCon = New ADODB.Connection
Set myRS = New ADODB.Recordset
myCon.ConnectionString = "driver={SQL Server}; server=ZYW; uid=sa; pwd=123456; database=school"
myCon.ConnectionTimeout = 10
myCon.Open
myRS.CursorLocation = adUseClient
myRS.Open "select * from student", myCon, adOpenKeyset, adLockOptimistic
Set TDBGrid1.DataSource = myRS
TDBGrid1.ReBind
Case 1
With TDBGrid1.PrintInfo
' 设置表头字体为斜体和表头内容
.PageHeaderFont.Italic = True
' 显示页脚
.PageFooter = "\tPage: \p"
' 预览
.PrintPreview
End With
End Select
End Sub
重新建立工程加入Adodc并正确连接到运行在后台SQL上的表,加入TDataLite将它的DataSource设为Adcdc,加入TDBGrid想将它的DataSoure设为TDataLite可是此时出现错误提示:没有找到于此使用者兼容的数据源,请添加一个固有的数据控件或远程数据控件到窗体。如果使用Data控件就没有问题,但是我觉得我使用ADO控件的方法和软件自带的例子没有多少出入。
唉!!!! 不好使,就是不好使。请问各位我到底做错了什么?? 谢谢!!我的E-mail:zzzbbb0281@sina.com.cn