Re: Invalid attempt to read when no data is present
From: Marina (someone_at_nospam.com)
Date: 02/24/05
- Next message: Vaibhav: "Re: ASP.NET/Crystal Reports Logon Failed"
- Previous message: Brian Ciarcia: "Re: Loop through a Plain Radio Button in ASP.NET"
- In reply to: Andy Sutorius: "Invalid attempt to read when no data is present"
- Messages sorted by: [ date ] [ thread ]
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
>
>
- Next message: Vaibhav: "Re: ASP.NET/Crystal Reports Logon Failed"
- Previous message: Brian Ciarcia: "Re: Loop through a Plain Radio Button in ASP.NET"
- In reply to: Andy Sutorius: "Invalid attempt to read when no data is present"
- Messages sorted by: [ date ] [ thread ]