views:

338

answers:

2

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

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")
     }

How can I check that? Please Help me! Thanks all in advcance!

+3  A: 
if(drd.HasRows)
{
   //....
}
richeym
Thanks a lot! it works!
RedsDevils
A: 

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

ZippyV
But I want to check before drd.read()!
RedsDevils