Dim sql As String
Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset sql = "select * from 电力能耗表 where 日期 between '=" & BeginDate.Value & "' and '" & EndDate.Value & "'"
Set rs = ConnWZ.Execute(sql)
问题是:每次执行到Set rs = ConnWZ.Execute(sql)这条语句的时候就会报错----Run-time error '91':
object variable or with block variable not set
我在module中已经定义了connection,而且已经open了,我不知道哪里出错了,也试过很多的方法不能解决,谢谢帮助.mail:[email protected].
Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset sql = "select * from 电力能耗表 where 日期 between '=" & BeginDate.Value & "' and '" & EndDate.Value & "'"
Set rs = ConnWZ.Execute(sql)
问题是:每次执行到Set rs = ConnWZ.Execute(sql)这条语句的时候就会报错----Run-time error '91':
object variable or with block variable not set
我在module中已经定义了connection,而且已经open了,我不知道哪里出错了,也试过很多的方法不能解决,谢谢帮助.mail:[email protected].
rs.open sql,connwz,adopenkeyset,adlockreadonly
if rs.recordcount>0 then
...
end if
set rs=nothing
operation is not allowed on an object referencing a closed or invalid connection.
Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset sql = "select * from 电力能耗表 where 日期 between '=" & BeginDate.Value & "' and '" & EndDate.Value & "'"
rs.open sql,ConnWZ,OpenDynamic ,adLockOptimistic
不能对已经关闭或者非法的连接执行这样的操作你的连接断了,需要重新连接。其实既然连接是全局变量,最好不要断开,除非程序退出了。如果要断开,那就需要重新建立连接。
msn地址:[email protected]
Set rs = New ADODB.Recordset
ConnWZ.Open "dsn=Facility;uid=;pwd=;"
ConnWZ.CursorLocation = adUseClient
rs.CursorType = adOpenStatic
rs.LockType = adLockOptimistic
MsgBox "ok"
Else
MsgBox "no"
End If用这段代码判断,执行到第一行时就报错Run-time error '3001'
Arguments are of the wrong type,are out of acceptable range,or are in conflict with one another
'Dim rs As ADODB.Recordset
'Set rs = New ADODB.Recordset'不要 sql = "select * from 电力能耗表 where 日期 between '=" & BeginDate.Value & "' and '" & EndDate.Value & "'"
Set rs = ConnWZ.Execute(sql)
改
Dim ConnWZ = New ADODB.Connection
ConnWZ.CursorLocation = adUseClient
交换一下他们的位置
打开连接问题
Arguments are of the wrong type,are out of acceptable range,or are in conflict with one another
它说明何问题是没有打开还是它根本不认识这个对象?
stae改為state
set myConn=new adodb.connection
myconn.open "dsn=;uid=;,pwd="
myConn.adcursorlocation=adUserClientdim rs as adodb.recordset
set rs=new adodb.recordset
rs.open "select * from 电力能耗表 where 日期 between '=" & BeginDate.Value & "' and '" & EndDate.Value & "'",myConn, adOpenstatic,adlockoptimstic
set rs=nothing
rs.close我想这样子应该没有问题,不过我建议你表名最好用英文啦
"dsn=Facility;uid=;pwd=;"
鼠标移到recordset的ActiveConnection时,自动跳出
rs.ActiveConnection="Provider=MSDASQL.1;Extended Properties="DSN=Facility...""
我怀疑是不是我的Open参数写错了,Provider该指定是
Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\My Documents\Facility\facility.mdb;
我不太明白的是Open参数直接写"dsn=Facility;uid=;pwd=;"它默认的provider是哪个?
万分感谢:)
别的参数就不需要了你们公司里面应该有前辈啦
报错:
Run-time error '-2147467259(80004005)':
Could not find installable ISAM
错误语句:sql = "select * from 电力能耗表 where 日期 between '=" & BeginDate.Value & "' and '" & EndDate.Value & "'"
正确语句:sql = "select * from 电力能耗表 where 日期 between # " & BeginDate.Value & " # and # " & EndDate.Value & " #"原因:数据库为ACCESS,则日期型字段要使用#,如果数据库为SQL,则日期型字段要使用'.