| | |
Error in reading DataReader
Please support our C# advertiser: Intel Parallel Studio Home
Thread Solved |
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
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
You missed Read() method.
c# Syntax (Toggle Plain Text)
if (dataReader4.Read()) var=dataReader4.IsDBNull(0); }
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.
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/
Indian Developer
http://falaque.wordpress.com/
•
•
Join Date: Jul 2008
Posts: 1
Reputation:
Solved Threads: 1
•
•
•
•
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!!! •
•
Join Date: Mar 2008
Posts: 6
Reputation:
Solved Threads: 2
It looks like you start using the reader without reading some data first.
Cheers,
Dennis
c# Syntax (Toggle Plain Text)
void ReadData(SqlConnection conn, string sql) SqlDataReader datareader; SqlCommand cmd = new SqlCommand(); cmd.Connection = conn; cmd.CommandText = sql; datareader = cmd.ExecuteReader(); while (datareader.Read()) { // perform your code here } }
Cheers,
Dennis
![]() |
Similar Threads
- Error while reading hard disk mbr through absread() (C++)
- IDE #1 error on bootup (Toshiba laptop) (Storage)
- Error reading zip (PHP)
- Cannot Find Server or DNS Error (Viruses, Spyware and other Nasties)
- reading a file into code (Java)
- Error occured during the file system check. (*nix Software)
- Windows ME startup error (Windows 95 / 98 / Me)
- DNS Server error on IE6 (Viruses, Spyware and other Nasties)
Other Threads in the C# Forum
- Previous Thread: Access to member
- Next Thread: calculator in c# !!!
| Thread Tools | Search this Thread |
.net access ado.net algorithm array barchart bitmap box broadcast buttons c# chat check checkbox client color combobox control conversion cryptographyc#winformsencryption csharp custom database datagrid datagridview dataset datetime degrees development draganddrop drawing encryption enum event excel file files form format forms function gdi+ httpwebrequest image index input install java keypress label list listbox listener mandelbrot math mouseclick mysql networking operator path photoshop picturebox pixelinversion post prime programming radians regex remote remoting richtextbox save saving serialization server sleep socket sql statistics stream string table tcp text textbox thread time timer treeview update usercontrol validate validation view visualstudio webbrowser windows winforms wpf xml






