急,请VB高手指教!编译总是提示:没有为指定对象设置记录源!
下面是我的代码:想通过查询方式,在DataGrid中显示信息!
Private Sub DataGrid1_Click()
Dim sql As String
Dim rst As ADODB.Recordset
Dim mydboper As New DBOperation
mydboper.DB_Connect
sql = "SELECT bookid,name FROM Book WHERE borrowerid= ' " + Trim(txtBorrId) + " ' "
Set rst = mydboper.querySQL(sql)
Adodc1.RecordSource = query_sql
'Adodc1.Refresh
Set DataGrid1.DataSource = Adodc1
'DataGrid1.ReBind
rst.Close
mydboper.DB_DisConnect
End Sub
请问是哪个地方出了问题?该怎么修改?谢谢~~~~急~~~
[解决办法]
Option Explicit
Dim db As ADODB.Connection
Dim rst As ADODB.Recordset
Private Sub Command1_Click()
Set db = New ADODB.Connection
Set rst = New ADODB.Recordset
Dim sql As String
sql = "SELECT bookid,name FROM Book WHERE borrowerid= ' " + Trim(txtBorrId) + " ' "
db.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= " & App.Path & "\hxrkgl.mdb;Persist Security Info=False "
db.Open
rst.CursorLocation = adUseClient
rst.Open sql, db, adOpenStatic, adLockReadOnly
Set DataGrid1.DataSource = rst
End Sub
[解决办法]
此种方法已经很少使用,VB自带的DataGrid功能很少(如排序\拖动列等).本人有成熟的代码.如有意请联系Email:clt_qd@yahoo.com.cn
QQ:6367109