COunt records/rows returned.

P

Paul

I use the following to populate a listbox (exert) :

sql = "Select CONTACT_ID, CONTACT_NAME from tblContact WHERE CONTACT_DELETE
<> 1 AND CONTACT_NAME LIKE " & "'%" & Me.txtSearchName.Text & "%'" & " order
by CONTACT_NAME"
' Me.Label1.Text = sql
Dim conn As New OdbcConnection(strConn)
Dim Cmd As New OdbcCommand(sql, conn)
Dim objDR As OdbcDataReader
conn.Open()
objDR = Cmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection)
emplist.DataSource = objDR
emplist.DataValueField = "CONTACT_ID"
emplist.DataTextField = "CONTACT_NAME"
emplist.DataBind()

Can someone tell me how I would detect if there where no records returned ?

Thanks in Advance
 
W

William Ryan

In VS 2003, the DataReader has a Property .HasRows...boolean so if
dr.HasRows then you got something.

In 2002, you'll need to iterate through it and get a count manually which
doesn't look like it fits well with what you are doing. Hopefully you have
2003. But if you don't, it'll only be a few more lines.

HTH,

Bill
 
W

William Ryan

Armin:

You are going to have to iterate then. While (dr.Read and myBool)

'then in the first pass, set myBool to false, if it executes at all then you
have rows...
Paul said:
As william said.

I dont have 2003.
 
A

Armin Zingler

William Ryan said:
Armin:

You are going to have to iterate then. While (dr.Read and myBool)

'then in the first pass, set myBool to false, if it executes at all
then you have rows...


I didn't know this here - I'd only have known in the ADO.NET group. ;-)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top