开发者

How Can I check whether DataReader has Data or not?

开发者 https://www.devze.com 2022-12-12 14:08 出处:网络
Again I have problem with checking whether DataReader object has data or not? Dim cmd as SqlCommand Dim drd as SqlDataReader

Again I have problem with checking whether DataReader object has data or not?

Dim cmd as SqlCommand
Dim drd as SqlDataReader

      cmd = New SqlCommand ("SELEC开发者_StackOverflowT * 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")
     }

How can I check that? Please Help me! Thank in advance!


if(drd.HasRows)
{
   //....
}


Yes you can with drd.read()

Like:

If drd.read() Then
    ...do things with data...
Else
    ...show message box... or just skip.
End If


drd.Read() will return False when there is no data. You don't have to change your code.

0

精彩评论

暂无评论...
验证码 换一张
取 消