让VB快速读取数据库的函数中,为什么"rs.MoveFirst "会出错啊?
Set rs = GetDb("set.mdb", "select * from Set_SmtpMail")
MsgBox rs("smtpname")
rs.MoveFirst ' 为什么会在这句上出错啊?
MsgBox rs("smtpname")
Public Function GetDb(ByVal aDbFile As String, ByVal aSql As String)
Dim Conn, SQL
Dim ConnectionString As String
Set Conn = CreateObject("ADODB.Connection") '连接数据库
Conn.Open "provider=Microsoft.Jet.oledb.4.0;" & "data source=" & aDbFile
Dim rs As New ADODB.Recordset
SQL = aSql
rs.Open SQL, Conn, 1, 2
GetDb = rsSet rs = Nothing
Set Conn = Nothing
End Function
Set rs = GetDb("set.mdb", "select * from Set_SmtpMail")
MsgBox rs("smtpname")
rs.MoveFirst ' 为什么会在这句上出错啊?
MsgBox rs("smtpname")
Public Function GetDb(ByVal aDbFile As String, ByVal aSql As String)
Dim Conn, SQL
Dim ConnectionString As String
Set Conn = CreateObject("ADODB.Connection") '连接数据库
Conn.Open "provider=Microsoft.Jet.oledb.4.0;" & "data source=" & aDbFile
Dim rs As New ADODB.Recordset
SQL = aSql
rs.Open SQL, Conn, 1, 2
GetDb = rsSet rs = Nothing
Set Conn = Nothing
End Function
if rs.BOF=false then
rs.Movefirst
End if
if rs.recordcount>0 then'必须进行判断
MsgBox rs("smtpname")
rs.MoveFirst ' 为什么会在这句上出错啊?
MsgBox rs("smtpname
........
end if
研究一下1代表啥意思,2代表啥意思?
1,2这个问题不大,一般在客户端游标时,1,2可能不支持,但是ado会自动修改,使用最合适的参数代替之
Set Conn = Nothing
End Function已经释放对像 再操作rs 当然出错了
Dim Conn, SQL
Dim ConnectionString As String
Set Conn = CreateObject("ADODB.Connection") '连接数据库
Conn.Open "provider=Microsoft.Jet.oledb.4.0;" & "data source=" & aDbFile
Dim rs As New ADODB.Recordset
SQL = aSql
rs.Open SQL, Conn, 1, 2
Set GetDb = rs.Clone(adLockReadOnly)Set rs = Nothing
Set Conn = Nothing
End Function