0

我有机会在迁移项目(VB 到 VB.NET)中工作。我对 RecordSet 功能感到困惑。在我们的项目中,我们根据场景使用 DataReader。但是在像 dsr.EOF 这样的循环案例中。

  Dim recordset As dao.RecordSet
If recordset .EOF Then
       '    '    msgbox "Please enter some number ", vbOKOnly, "Number Not Found"
       '    '    txtAdd.SetFocus
       '    '    Exit Sub
End If

如何将其转换为 VB.NET?我们需要写 If Not reader.Read 或 If reader.Read。

有什么可以帮助我的吗?

4

1 回答 1

1

我想你可能会追求的是以下

Dim reader As IDataReader
' <fill the reader with your query via an IDbCommand>
Dim dataFound As Boolean = false

Using reader = command.ExecuteQuery()
    While reader.Read()
        ' <perform your data processing here>
        dataFound = True
    End While

    If dataFound = False Then
        ' <Here you do your processing for the case where data was not found.>
    End If
End Using

或者,如果您只关注一行数据,那么我们有:

Dim reader As IDataReader
' <fill the reader with your query via an IDbCommand>

Using reader = command.ExecuteQuery()
    If reader.Read() Then
        ' <perform your data processing here>
    Else
        ' <Here you do your processing for the case where data was not found.>
    End While
End Using
于 2012-04-26T10:10:35.717 回答