让VB快速读取数据库的函数中,为什么"rs.MoveFirst "会出错啊?
让VB快速读取数据库的函数中,为什么"rs.MoveFirst"会出错啊?Setrs=GetDb("set.mdb","select*fromSet_SmtpMail")...
让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 = rs
Set 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 = rs
Set rs = Nothing
Set Conn = Nothing
End Function 展开
展开全部
If rs.recordcount>0 and rs.bof=False Then
rs.MoveFirst
End If
rs.MoveFirst
End If
更多追问追答
追问
记录总数有9条,但是用这个.MoveFirst 还是出错
监视了一下,函数返回的值好像不是记录集了,好像是一个集合一样的数值
返回的函数用记录集的函数操作不了了
追答
把 move 放函数里吧 函数的返回的不是 ADODB.RecordSet 类型啦
或者Public Function GetDb(ByVal aDbFile As String, ByVal aSql As String) As adodb.Recordset 试试
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询