请各位高手帮忙是数据库访问的问题,急等!!
下面这段代码先是访问数据库中的一个表test,可以访问成功并能添加数据。可是到了访问第二个表into时却提示rsycy!ycy = Trim(Combo1.Text)这句代码“对象变量或 With 块变量没有设置(错误 91)”,并且Set rsycy = ExecuteSQL(sqtd, msgtext)这句中的rsycy=nothing。请各位指点。其中ExecuteSQL(sqtd, msgtext)是一个访问sqlsever 2000的数据库函数。下面是代码:
Dim sqtd As String
Dim msgtext As String
Dim rsycy As ADODB.Recordset
sqtd = "select * from test "
Set rsycy = ExecuteSQL(sqtd, msgtext)
rsycy.AddNew
rsycy!jcl = Label6.Caption
rsycy!hph = Label5.Caption
rsycy!jc = Label9.Caption
rsycy!z_control = "0 "
rsycy!location = "one "
rsycy!time = Format(Now, "yyyy/mm/dd hh:mm:ss ")
rsycy.Update
rsycy.close
sqtd = "select ycy from into where jcl= ' " & Trim(Label6.Caption) & " ' "
Set rsycy = ExecuteSQL(sqtd, msgtext)
rsycy!ycy = Trim(Combo1.Text)
rsycy.Update
rsycy.close
[解决办法]
不好意思,问题在这里::
Dim rsycy As ADODB.Recordset
这里定义的rsycy 是一个变量,应修改为
Dim rsycy As New ADODB.Recordset
如此即可.