Dim res As ADODB.Recordset
sql = "select bookname,author,flno from book where bookname = '" & name & "' or author = '" & auth & "' or flno = '" & flo & "'"
res.Open sql, conn, adOpenKeyset, adLockReadOnly
Adodc1.RecordSource = sql
Adodc1.Refresh
Set res = Adodc1.Recordset
If res.RecordCount <> 0 Then
Set dg1.DataSource = res
dg1.Refresh
MsgBox "success"
Else
MsgBox "fail"
End If
res.Close
Set res = Nothing
这样写,有错误1:只能执行一次,不能连续查询,提示错误:对象打开时,操作不被允许。
错误2:datagrid中的纪录在弹出success提示框时可见,点击确定后不可见,这个原因我知道,是由res.close引起的,即把记录集关闭了,所以不能显示了以上代码如果去掉res.close:set res=nothing,那么依然有错误1:只能执行一次,不能连续查询!这到底该怎么写呢?急死人了,本来功能很简单的,可就是写不对,实现不了。。
哪位高人发表点意见吧?我都弄了两天了,还没弄出来。。
Set res = New ADODB.Recordset
sql = "select bookname,author,flno from book where bookname = '" & name & "' or author = '" & auth & "' or flno = '" & flo & "'"
res.Open sql, conn, adOpenKeyset, adLockReadOnly
Adodc1.RecordSource = sql
Adodc1.Refresh
Set res = Adodc1.Recordset
If res.RecordCount <> 0 Then
Set dg1.DataSource = res
dg1.Refresh
MsgBox "success"
Else
MsgBox "fail"
End If
res.Close
Set res = Nothing
这样写,有错误1:只能执行一次,不能连续查询,提示错误:对象打开时,操作不被允许。
错误2:datagrid中的纪录在弹出success提示框时可见,点击确定后不可见,这个原因我知道,是由res.close引起的,即把记录集关闭了,所以不能显示了以上代码如果去掉res.close:set res=nothing,那么依然有错误1:只能执行一次,不能连续查询!这到底该怎么写呢?急死人了,本来功能很简单的,可就是写不对,实现不了。。
哪位高人发表点意见吧?我都弄了两天了,还没弄出来。。
Set res = New ADODB.Recordset
sql = "select bookname,author,flno from book where bookname = '" & name & "' or author = '" & auth & "' or flno = '" & flo & "'"
if res.State = adStateOpen then res.Close
res.Open sql, conn, adOpenKeyset, adLockReadOnly
Adodc1.RecordSource = sql
Adodc1.Refresh
Set res = Adodc1.Recordset
If res.RecordCount <> 0 Then
Set dg1.DataSource = res
dg1.Refresh
MsgBox "success"
Else
MsgBox "fail"
End If
res.Close
Set res = Nothing
Public Sub main()
conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\wlj\db1.mdb;Persist Security Info=False"
End Sub