无法在 VB6 中处理 null 或空记录集
这一天我绞尽脑汁解决这个问题......我用谷歌搜索了解决方案,但没有一个解决我的问题......
代码是这样的:
Private Sub guh()
Dim oConn As Connection
Dim Record As Recordset
Dim SqlStr As String
SqlStr = "select * from dbo.Msg_History where Client_ID='2' AND Update_Msg='4'"
Set oConn = New Connection
With oConn
.CursorLocation = adUseClient
.CommandTimeout = 0
.Open "Provider=SQLOLEDB;Server=127.0.0.1;Initial Catalog=Table_Msg;UID=Admin;PWD="
End With
Set Record = oConn.Execute(SqlStr)
If IsNull(Record) Then
MsgBox "There are no records"
Else
MsgBox "There are records"
End If
oConn.Close
Set oConn = Nothing
End Sub
The sql statements is returned null recordset ..when i运行代码...它总是转到“else”条件,即MsgBox“有记录”行
我尝试更改该行:If IsNull(Record)然后
到
If IsNull(Record.Fields(0)。 Value) 然后
它会抛出这样的错误:-
error: 要么 BOF 或 EOF 为 true,要么当前记录已被删除。请求的操作需要当前记录。
我已检查 http://support.microsoft.com/kb/304267 并使用 eof 和bof 到条件...n仍然得到相同的错误..
请任何人帮助我...
It's been a day I've cracked my head to solve this....I've googled for solutions but none of it resolve my issue...
The code is like this:
Private Sub guh()
Dim oConn As Connection
Dim Record As Recordset
Dim SqlStr As String
SqlStr = "select * from dbo.Msg_History where Client_ID='2' AND Update_Msg='4'"
Set oConn = New Connection
With oConn
.CursorLocation = adUseClient
.CommandTimeout = 0
.Open "Provider=SQLOLEDB;Server=127.0.0.1;Initial Catalog=Table_Msg;UID=Admin;PWD="
End With
Set Record = oConn.Execute(SqlStr)
If IsNull(Record) Then
MsgBox "There are no records"
Else
MsgBox "There are records"
End If
oConn.Close
Set oConn = Nothing
End Sub
The sql statement is returning null recordset ..when i run the code...it always go to the "else" condition which is the line MsgBox "There are records"
I've tried change the line : If IsNull(Record) Then
to
If IsNull(Record.Fields(0).Value) Then
but then it throws an error like this:-
error: Either BOF or EOF is true, or the current record has been deleted. Requested operation requires a current record.
I've checked http://support.microsoft.com/kb/304267 and use eof and bof to the condition...n still get the same error..
please anyone help me...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我会使用这样的东西:
I would use something like this:
将此更改
为
Change this
to
我认为您可以测试
如果不是Record.Eof
。如果我没记错的话(已经很久了),它只适用于一种类型的光标,我认为它应该是
adUseServer
。 (编辑 不,实际上是 RecordCount 有这个问题)我会尝试挖掘一些旧代码来检查。
I think you can test for
if not Record.Eof
.If I recall correctly (it's been a long time), it only works with one type of cursor, I think it should be
adUseServer
. (EDIT No, it's actually RecordCount which has this problem)I'll try and dig out some old code to check.
感谢大家的回复:D ...无论如何稍后都会测试它...在我发布此回复时我还没有测试您的所有建议...我测试了这个: –
如果 Record.BOF 和 Record.EOF然后
这有效...
Thanks for the replies guys :D ...will test it later anyway...I havent's tested all of your suggestions at the time I'm posting this reply...I tested this: –
If Record.BOF And Record.EOF Then
and this works...