无法处理VB6中的null或空记录集
这一天我绞尽脑汁想解决这个问题……我在谷歌上搜索解决方案,但没有一个能解决我的问题 代码如下所示:无法处理VB6中的null或空记录集,vb6,null,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
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
' returns true if there is non empty recordset
Function isRSExists(rs) AS boolean
' has to exists as object
If Not rs Is Nothing Then
' has to be opened with recordset (could be empty)
If rs.State > 0 Then
' has to have some records
If Not rs.EOF Then
isRSExists = true
End If
End If
End If
End Function
sql语句返回空记录集..当我运行代码时…它总是转到“else”条件,即行MsgBox“There are records”
我尝试更改行:如果IsNull(记录),则
到
如果IsNull(记录字段(0).Value),则
但它会抛出这样一个错误:-
错误:BOF或EOF为真,或者当前记录已被删除。请求的操作需要当前记录
我已经检查并使用eof和bof的条件…n仍然得到相同的错误
请任何人帮帮我 如果不录制,我想您可以测试
。Eof
如果我没记错的话(已经很长时间了),它只适用于一种类型的游标,我认为应该是adUseServer
。(编辑否,实际上是RecordCount存在此问题)
我将尝试找出一些旧代码进行检查。我认为如果不记录,您可以测试
。Eof
如果我没记错的话(已经很长时间了),它只适用于一种类型的游标,我认为应该是adUseServer
。(编辑否,实际上是RecordCount存在此问题)
我将尝试找出一些旧代码进行检查。更改此代码
If IsNull(Record) Then
到
改变这个
If IsNull(Record) Then
到
我会用这样的方式:
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
' returns true if there is non empty recordset
Function isRSExists(rs) AS boolean
' has to exists as object
If Not rs Is Nothing Then
' has to be opened with recordset (could be empty)
If rs.State > 0 Then
' has to have some records
If Not rs.EOF Then
isRSExists = true
End If
End If
End If
End Function
我会用这样的方式:
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
' returns true if there is non empty recordset
Function isRSExists(rs) AS boolean
' has to exists as object
If Not rs Is Nothing Then
' has to be opened with recordset (could be empty)
If rs.State > 0 Then
' has to have some records
If Not rs.EOF Then
isRSExists = true
End If
End If
End If
End Function
谢谢你的回复,伙计们:D…无论如何,我稍后会测试它…在我发布这个回复的时候,我还没有测试你的所有建议…我测试了这个:– 如果是Record.BOF和Record.EOF,则
这是有效的…谢谢你的回复,伙计们:D…无论如何,稍后会测试它…我在发布此回复时还没有测试你的所有建议…我测试了此:—— 如果是Record.BOF和Record.EOF,则
这很有效…感谢您的反馈。您可以在答案或问题上添加注释,而不是创建新的“答案”。注意,你也可以通过投票来表达你的感激之情。如果一个问题提供了“答案”,你可以将其标记为已接受(用复选标记)。在我看来,@Grzegorz应该被选中。只需测试EOF或.RecordCount=0。也不需要测试转炉。测试EOF和BOF是旧技术中需要做的事情,例如DAO(和RDO?)很高兴,他们在设计ADO时解决了这个问题。Benjol:很抱歉……现在再次检查我的问题……那天我真的很忙……注意到……谢谢:)……但我想知道这句话是不是“If IsNull(Record)Then”不工作..我已经用另一个变量类型变量测试了这一行,并将其设置为null…它工作得很好..但是y它在记录集上失败了吗?谢谢你的反馈。您可以在答案或问题上添加注释,而不是创建新的“答案”。注意,你也可以通过投票来表达你的感激之情。如果有一个问题提供了“答案”,你可以将它标记为“接受”(带有复选标记)。在我看来,@Grzegorz应该被选中。只需测试EOF或.RecordCount=0。也不需要测试转炉。测试EOF和BOF是旧技术中需要做的事情,例如DAO(和RDO?)很高兴,他们在设计ADO时解决了这个问题。Benjol:很抱歉……现在再次检查我的问题……那天我真的很忙……注意到……谢谢:)……但我想知道这句话是不是“If IsNull(Record)Then”不工作..我已经用另一个变量类型变量测试了这一行,并将其设置为null…它工作得很好..但它在记录集上失败了吗?我认为这在上下文中是过分的。当
rs为Nothing
时,他们可能希望出现异常,因为如果从普通SELECT
中没有返回任何记录集,则表明存在严重的环境问题(例如,表已被删除)。我假设在删除表的情况下,执行
引发异常。。。例如,从问题(纯SQL)来看,这太过分了,但如果调用存储过程或VB函数返回记录集的结果不是这样。为什么我要在2016年的时候用谷歌搜索vb6呢@因为我们必须维护和修复旧软件!!(现在是2017年!!)我认为这在上下文中是矫枉过正的。当rs为Nothing
时,他们可能希望出现异常,因为如果从普通SELECT
中没有返回任何记录集,则表明存在严重的环境问题(例如,表已被删除)。我假设在删除表的情况下,执行
引发异常。。。例如,从问题(纯SQL)来看,这太过分了,但如果调用存储过程或VB函数返回记录集的结果不是这样。为什么我要在2016年的时候用谷歌搜索vb6呢@因为我们必须维护和修复旧软件!!(现在是2017年!!)