数据库查询小问题,路过不要错过~~
报错信息:bof或eof中有一个是“真”,或者当前的记录已被删除,所需的操作要求一个当前的记录。
代码:
Set conn1 = New ADODB.Connection
conn1.Open DrugsManagement.Adodc1.ConnectionString
Rs1.ActiveConnection = conn1.ConnectionString
If DrugsManagement.txtDrugsName <> " " Then
Rs1.Source = "select * from DrugsDataBase where DrugsName like '* " & DrugsManagement.txtDrugsName & "* ' "
Rs1.Open
End If
Debug.Print Rs1( "ID ").Value
On Error Resume Next
Rs1.Close
Set Rs1 = Nothing
Set conn = Nothing
报错语句:Debug.Print Rs1( "ID ").Value
信息:确定数据库中有记录,select语句在access数据库中查询出有记录,但是在程序运行中却报错,请问为什么?怎样解决?
[解决办法]
Rs1.Source = "select * from DrugsDataBase where DrugsName like '% " & DrugsManagement.txtDrugsName & "% ' "