By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,165 Members | 1,403 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,165 IT Pros & Developers. It's quick & easy.

COunt records/rows returned.

P: n/a
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.Clos eConnection)
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

Nov 20 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
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
"Paul" <pa**@themedialounge.com> wrote in message
news:uu*************@tk2msftngp13.phx.gbl...
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.Clos eConnection)
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

Nov 20 '05 #2

P: n/a
As william said.

I dont have 2003.

"Armin Zingler" <az*******@freenet.de> wrote in message
news:u7*************@tk2msftngp13.phx.gbl...
"Paul" <pa**@themedialounge.com> schrieb
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.Clos eConnection)
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 ?


It's not hard to find when having a look at the DataReader's members:
objDR.HasRows
--
Armin

Nov 20 '05 #3

P: n/a
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" <pa**@themedialounge.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
As william said.

I dont have 2003.

"Armin Zingler" <az*******@freenet.de> wrote in message
news:u7*************@tk2msftngp13.phx.gbl...
"Paul" <pa**@themedialounge.com> schrieb
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.Clos eConnection)
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 ?


It's not hard to find when having a look at the DataReader's members:
objDR.HasRows
--
Armin


Nov 20 '05 #4

P: n/a
"William Ryan" <do********@comcast.nospam.net> schrieb
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. ;-)
--
Armin

Nov 20 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.