PC Review


Reply
Thread Tools Rate Thread

Datareader, there is no data...

 
 
Arjen
Guest
Posts: n/a
 
      30th Jul 2003
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!


 
Reply With Quote
 
 
 
 
Arjen
Guest
Posts: n/a
 
      30th Jul 2003
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" <(E-Mail Removed)> schreef in bericht
news:#(E-Mail Removed)...
> 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" <(E-Mail Removed)> wrote in message
> news:bg7ufi$mro$(E-Mail Removed)1.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!
> >
> >

>
>



 
Reply With Quote
 
 
 
 
PJ
Guest
Posts: n/a
 
      30th Jul 2003
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" <(E-Mail Removed)> wrote in message
news:bg834s$62h$(E-Mail Removed)1.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" <(E-Mail Removed)> schreef in bericht
> news:#(E-Mail Removed)...
> > 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" <(E-Mail Removed)> wrote in message
> > news:bg7ufi$mro$(E-Mail Removed)1.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!
> > >
> > >

> >
> >

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Still using IE? There are more powerfull stuff out there. Kenny S Windows XP Help 7 18th Jun 2004 01:49 PM
IS ANYBODY OUT THERE...there....there....there pooder Microsoft Windows 2000 Games 4 28th Mar 2004 03:51 PM
numeric keypad issue- HELP! IS THERE ANYONE OUT THERE??? GSteven Windows XP Help 3 13th Jan 2004 10:34 PM
files there but not there and folders making themselves read only by themselves gravy Windows XP Help 0 14th Nov 2003 05:35 AM
is there a script that will log people off in there is inactivity for certain period Ankit Shah Windows XP Security 0 15th Oct 2003 06:40 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:16 AM.