2

我再次在检查 DataReader 对象是否有数据时遇到问题?

Dim cmd as SqlCommand
Dim drd as SqlDataReader

      cmd = New SqlCommand ("SELECT * FROM Stock", conx)
      drd = cmd.ExecuteReader()

      ''HERE I WOULD LIKE TO CHECK WHETHER drd has Data or not

     While (drd.Read())
     {
          txtName.Text = drd.Item("StockName")
     }

我该如何检查?请帮我!预先感谢!

4

3 回答 3

10
if(drd.HasRows)
{
   //....
}
于 2009-11-28T11:06:34.187 回答
1

是的,你可以使用 drd.read()

喜欢:

If drd.read() Then
    ...do things with data...
Else
    ...show message box... or just skip.
End If
于 2012-03-28T15:22:30.020 回答
0

没有数据时,drd.Read() 将返回 False。您不必更改代码。

于 2009-11-28T11:07:02.487 回答