Re: Invalid attempt to read when no data is present
From: Kevin Spencer (kevin_at_DIESPAMMERSDIEtakempis.com)
Date: 02/24/05
- Next message: Kevin Spencer: "Re: uploading files from users"
- Previous message: mollyf_at_hotmail.com: "ASP.NET/Crystal Reports Logon Failed"
- In reply to: Andy Sutorius: "Invalid attempt to read when no data is present"
- Next in thread: Andy Sutorius: "Re: Invalid attempt to read when no data is present"
- Reply: Andy Sutorius: "Re: Invalid attempt to read when no data is present"
- Messages sorted by: [ date ] [ thread ]
Date: Thu, 24 Feb 2005 13:43:08 -0500
> string strSubject = Convert.ToString(dtrEmail["subject"]);
> string strContent = Convert.ToString(dtrEmail["content"]);
Are you checking for NULL values before attempting to convert them to
strings? A NULL cannot be converted to a string. Example:
string strSubject;
int ordinal;
ordinal = dtrEmail.GetOrdinal("subject");
if (!dtrEmail.IsDbNull(ordinal)
strSubject = dtrEmail.GetString(ordinal);
else
strSubject = "";
-- HTH, Kevin Spencer Microsoft MVP .Net Developer Neither a follower nor a lender be. "Andy Sutorius" <andy@sutorius.com> wrote in message news:GCoTd.1391$ha.23643@twister.southeast.rr.com... > Hi, > > I am getting the error "Invalid attempt to read when no data is present" > when I run the following code. I have checked the sql and it is returning > data. What am I missing? > > string sqlGetEmail = "SELECT content, subject FROM tblContent WHERE id = > " + Convert.ToInt16(ddlChooseEmail.SelectedValue.ToString()); > SqlCommand cmdGetEmail = new SqlCommand(sqlGetEmail, strConnString); > SqlDataReader dtrEmail = cmdGetEmail.ExecuteReader(); > > string strSubject = Convert.ToString(dtrEmail["subject"]); > string strContent = Convert.ToString(dtrEmail["content"]); > > dtrEmail.Close(); > > > Thanks, > > Andy > >
- Next message: Kevin Spencer: "Re: uploading files from users"
- Previous message: mollyf_at_hotmail.com: "ASP.NET/Crystal Reports Logon Failed"
- In reply to: Andy Sutorius: "Invalid attempt to read when no data is present"
- Next in thread: Andy Sutorius: "Re: Invalid attempt to read when no data is present"
- Reply: Andy Sutorius: "Re: Invalid attempt to read when no data is present"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|