943,602 Members | Top Members by Rank

Ad:
  • C# Discussion Thread
  • Marked Solved
  • Views: 1028
  • C# RSS
Jul 23rd, 2009
0

Error in reading DataReader

Expand 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
Similar Threads
Reputation Points: 12
Solved Threads: 1
Junior Poster
Tank50 is offline Offline
124 posts
since Aug 2008
Jul 23rd, 2009
1

Re: Error in reading DataReader

You missed Read() method.
c# Syntax (Toggle Plain Text)
  1. if (dataReader4.Read())
  2. var=dataReader4.IsDBNull(0);
  3. }
Moderator
Reputation Points: 2136
Solved Threads: 1228
Posting Genius
adatapost is offline Offline
6,527 posts
since Oct 2008
Jul 23rd, 2009
1

Re: Error in reading DataReader

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.
Reputation Points: 165
Solved Threads: 59
Posting Pro in Training
DangerDev is offline Offline
485 posts
since Jan 2008
Jul 23rd, 2009
0

Re: Error in reading DataReader

Click to Expand / Collapse  Quote originally posted by Tank50 ...
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!!!
Reputation Points: 10
Solved Threads: 1
Newbie Poster
maestridaniele is offline Offline
1 posts
since Jul 2008
Jul 23rd, 2009
0

Re: Error in reading DataReader

It looks like you start using the reader without reading some data first.

c# Syntax (Toggle Plain Text)
  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
Reputation Points: 10
Solved Threads: 2
Newbie Poster
djjaries is offline Offline
6 posts
since Mar 2008
Jul 29th, 2009
0

Re: Error in reading DataReader

Hi

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


Tank50
Reputation Points: 12
Solved Threads: 1
Junior Poster
Tank50 is offline Offline
124 posts
since Aug 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C# Forum Timeline: Access to member
Next Thread in C# Forum Timeline: calculator in c# !!!





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC