Re: Invalid attempt to read when no data is present

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

From: Marina (someone_at_nospam.com)
Date: 02/24/05


Date: Thu, 24 Feb 2005 14:33:10 -0500

You need to call the Read method on the SqlDataReader before trying to get
data from it. And if the Read method returns False, no rows were returned.

"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
>
>


Quantcast