473,386 Members | 1,753 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Datareader, there is no data...

Hello,

How can I check the recordcount?

Here is a little bit of my code:
// Load first row into Datareader
dr.Read();

if (dr["Category"].ToString() == "xmlsrc") {

When I do this I get an error because there is no data... it only have to
check this dr["Category"].ToString() == "xmlsrc") if there is data.
How can I do that?

Thanks!
Nov 17 '05 #1
2 2485
When I search for your best practice with google.com I don't find al lot of
material.

http://www.google.nl/search?hl=nl&ie...ColumnEnum&lr=

What namespace do I have to use for ColumnEnum?

Thanks!

"PJ" <pj*********@hotmail.com> schreef in bericht
news:#V**************@TK2MSFTNGP10.phx.gbl...
the .Read() method returns false if it has reached the end of it's record
stream so your code should be

if ( dr.Read() )
{
//perform actions on row
}

and...btw, use enums rather than strings to access your columns...it's
quicker

if ( (string)dr[Convert.ToInt32(ColumnEnum.Category)] == "xmlsrc" )
//...

"Arjen" <bo*****@hotmail.com> wrote in message
news:bg**********@news4.tilbu1.nb.home.nl...
Hello,

How can I check the recordcount?

Here is a little bit of my code:
// Load first row into Datareader
dr.Read();

if (dr["Category"].ToString() == "xmlsrc") {

When I do this I get an error because there is no data... it only have to check this dr["Category"].ToString() == "xmlsrc") if there is data.
How can I do that?

Thanks!


Nov 17 '05 #2
PJ
ColumnEnum was just an example of an enum you would create to access the
columns in your SqlDataReader

enum ColumnEnum
{
Id, Category, etc
}

this way you are accessing the columns by their int index, rather than their
name, which is obviously faster.

"Arjen" <bo*****@hotmail.com> wrote in message
news:bg**********@news2.tilbu1.nb.home.nl...
When I search for your best practice with google.com I don't find al lot of material.

http://www.google.nl/search?hl=nl&ie...ColumnEnum&lr=

What namespace do I have to use for ColumnEnum?

Thanks!

"PJ" <pj*********@hotmail.com> schreef in bericht
news:#V**************@TK2MSFTNGP10.phx.gbl...
the .Read() method returns false if it has reached the end of it's record
stream so your code should be

if ( dr.Read() )
{
//perform actions on row
}

and...btw, use enums rather than strings to access your columns...it's
quicker

if ( (string)dr[Convert.ToInt32(ColumnEnum.Category)] == "xmlsrc" )
//...

"Arjen" <bo*****@hotmail.com> wrote in message
news:bg**********@news4.tilbu1.nb.home.nl...
Hello,

How can I check the recordcount?

Here is a little bit of my code:
// Load first row into Datareader
dr.Read();

if (dr["Category"].ToString() == "xmlsrc") {

When I do this I get an error because there is no data... it only have

to check this dr["Category"].ToString() == "xmlsrc") if there is data.
How can I do that?

Thanks!



Nov 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Yasutaka Ito | last post by:
Hi, My friend had a little confusion about the working of DataReader after reading an article from MSDN. Following is a message from him... <!-- Message starts --> I was going thru DataReader...
20
by: Mark | last post by:
Hi all, quick question , a DataView is memory resident "view" of data in a data table therefore once populated you can close the connection to the database. Garbage collection can then be used to...
4
by: Shapper | last post by:
Hello, I have created a datareader function in a asp.net/vb web site. The datareader returns only one record with 2 fields: and In the same aspx.vb I want to use this values as follows:...
6
by: Yasutaka Ito | last post by:
Hi, My friend had a little confusion about the working of DataReader after reading an article from MSDN. Following is a message from him... <!-- Message starts --> I was going thru DataReader...
3
by: =?Utf-8?B?UGV0ZXI=?= | last post by:
I'm trying to add a datagridview control to a Windows Form to display read-only information in visual basic 2005. My understanding is that datareader will be faster for this purpose. I have the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.