帮别人问个简单问题,解决后马上给分!

vc_love 2003-09-24 11:05:01
Dim mrc As ADODB.Recordset
Set mrc = New ADODB.Recordset
Set mrc = ExecuteSQL(txtsql)

'问题?当这时ExecuteSQL中返回为nothing 时
'下面这句话会出错,问如何判断mrc值是有效的呢?

If mrc.EOF = False Then
End If
Set mrc = Nothing
...全文
50 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
vc_love 2003-09-24
  • 打赏
  • 举报
回复
ExecuteSQL是自己定义的一个函数了!
of123 2003-09-24
  • 打赏
  • 举报
回复
Set mrc = ExecuteSQL(txtsql)有两种情况:

1 txtsql是查询语句,返回记录集
2 txtsql是数据库操纵语句(例如delete from, update, alter table等等),不返回记录集。

我的建议,对于第2种语句不要赋值给 mrc:
Call ExecuteSQL(txtsql)

如果一定要这么做,先判断一下:

Set mrc = ExecuteSQL(txtsql)

If IsNull(mrc) Then Exit Sub

If Not mrc.EOF Then
......
End If
Set mrc = Nothing
liaorui 2003-09-24
  • 打赏
  • 举报
回复
不好意思,看错你的意思了。你这样吧,我给你个函数,如果返回TRUE,就执行下一步

Function SqlCount(strsql As String) As Boolean

Dim i As Integer

Set rc = New ADODB.Recordset
i = 0
Do While Not rc.EOF
i = i + 1
Loop
If i = 0 Then
SqlCount = False
Else
SqlCount = True
End If

End Function
vc_love 2003-09-24
  • 打赏
  • 举报
回复
OK!解决!散分
佛的光辉 2003-09-24
  • 打赏
  • 举报
回复
楼主的程序不对阿
ExecuteSQL应该是DAO的方法,mrc又被定义为ADODB.Recordset
怎么回事
vc_love 2003-09-24
  • 打赏
  • 举报
回复
不行啊!

ExecuteSQL(txtsql) 没有出错

xx=mrc.Fields.Count
抱错:
Object variable or With block variable not set (Error 91)
miranda516 2003-09-24
  • 打赏
  • 举报
回复
If not mrc.EOF and not mrc.Bof = False Then
.....
End If
Garfield 2003-09-24
  • 打赏
  • 举报
回复
If not mrc is nothing then
'mrc 有效
End if
strongfisher 2003-09-24
  • 打赏
  • 举报
回复
if mrc is nothing then
exit sub
end if
liaorui 2003-09-24
  • 打赏
  • 举报
回复
mrc.Fields.Count

不过前提是要 ExecuteSQL(txtsql) 不出错

1,217

社区成员

发帖
与我相关
我的任务
社区描述
VB 数据库(包含打印,安装,报表)
社区管理员
  • 数据库(包含打印,安装,报表)社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧