Error in reading DataReader

Please support our C# advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Aug 2008
Posts: 96
Reputation: Tank50 is an unknown quantity at this point 
Solved Threads: 1
Tank50's Avatar
Tank50 Tank50 is offline Offline
Junior Poster in Training

Error in reading DataReader

 
0
  #1
Jul 23rd, 2009
Hi

I want to read the content in datareader.So I use below coding to do that
if (dataReader4.IsDBNull(0)){

}
but I run above coding it gave me an error meassage.The error Meassage is
"Invalid attempt to read when no data is present".

then I use below coding
dataReader4["Email"]==null
but It also gave me above error meassage.There is no record for that field,that only for one record,for othere records there are email address.

Thanks
Tank50
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 2,668
Reputation: adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of 
Solved Threads: 478
Moderator
adatapost's Avatar
adatapost adatapost is offline Offline
Posting Maven

Re: Error in reading DataReader

 
1
  #2
Jul 23rd, 2009
You missed Read() method.
  1. if (dataReader4.Read())
  2. var=dataReader4.IsDBNull(0);
  3. }
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 483
Reputation: DangerDev has a spectacular aura about DangerDev has a spectacular aura about 
Solved Threads: 58
DangerDev's Avatar
DangerDev DangerDev is offline Offline
Posting Pro in Training

Re: Error in reading DataReader

 
1
  #3
Jul 23rd, 2009
Hi,
Read example here. It will help you. You have to call dataReader4.Read() before reading it. If still problem persist please post code what you have done so far.
Freedom in the Mind, Faith in the words.. Pride in our Souls...
Indian Developer
http://falaque.wordpress.com/
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 1
Reputation: maestridaniele is an unknown quantity at this point 
Solved Threads: 1
maestridaniele maestridaniele is offline Offline
Newbie Poster

Re: Error in reading DataReader

 
0
  #4
Jul 23rd, 2009
Originally Posted by Tank50 View Post
Hi

I want to read the content in datareader.So I use below coding to do that
if (dataReader4.IsDBNull(0)){

}
but I run above coding it gave me an error meassage.The error Meassage is
"Invalid attempt to read when no data is present".

then I use below coding
dataReader4["Email"]==null
but It also gave me above error meassage.There is no record for that field,that only for one record,for othere records there are email address.

Thanks
Tank50
//****************************************************
Hi,
try this code to read datareader...

// Instance a new object
Object a = new Object();

// Check if datareader is null
if (datareader == null)
return;

// Get data from datareader
while (datareader.Read())
{
// Code example...
a = datareader.GetValue(0);
}

Hope it works for you...
See ya!!!
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 6
Reputation: djjaries is an unknown quantity at this point 
Solved Threads: 2
djjaries djjaries is offline Offline
Newbie Poster

Re: Error in reading DataReader

 
0
  #5
Jul 23rd, 2009
It looks like you start using the reader without reading some data first.

  1. void ReadData(SqlConnection conn, string sql)
  2. SqlDataReader datareader;
  3. SqlCommand cmd = new SqlCommand();
  4. cmd.Connection = conn;
  5. cmd.CommandText = sql;
  6. datareader = cmd.ExecuteReader();
  7. while (datareader.Read()) {
  8. // perform your code here
  9. }
  10. }

Cheers,
Dennis
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 96
Reputation: Tank50 is an unknown quantity at this point 
Solved Threads: 1
Tank50's Avatar
Tank50 Tank50 is offline Offline
Junior Poster in Training

Re: Error in reading DataReader

 
0
  #6
Jul 29th, 2009
Hi

Thanks guys.I was in greate trouble coz of this error meassage.Now it ok ,I miss datareader.Read() part.


Tank50
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C# Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC