ورود

View Full Version : سوال: دلیل این ارور چیه؟ Invalid attempt to read when no data is present.



dontspeak
سه شنبه 27 اردیبهشت 1390, 19:41 عصر
سلام.
من یه db دارم تیبل دارم به اسم editor دوتا ستونم توش داره به اسم id,fldContent خوب حالا این کدو نوشتم.
protected void Page_Load(object sender, EventArgs e)
{
Label1.Text = Editor1.Content;
SqlConnection scon = new SqlConnection(@"Data Source=.\sqlexpress;initial catalog = allTest;integrated Security=true");
scon.Open();

if (Page.IsPostBack)
{
string update = string.Format("update editor set fldContent={0} where id={1}", Editor1.Content.ToString(), 1);
SqlCommand scom = new SqlCommand(update, scon);
scom.ExecuteNonQuery();

}
else
{
string strselect = string.Format("select fldContent from editor where id = 1");
SqlDataReader myreader = null;
SqlCommand scom = new SqlCommand(strselect, scon);
myreader = scom.ExecuteReader();

Editor1.Content = myreader["fldContent"].ToString();
}
scon.Close();
}
توی خط
Editor1.Content = myreader["fldContent"].ToString();
این ارور میده:
Invalid attempt to read when no data is present
من همیشه می نوشتم ولی الان نمی دونم مشکل کجاست چرا گیر کرده؟:متفکر:

dontspeak
سه شنبه 27 اردیبهشت 1390, 20:13 عصر
یه چیزی که الان یادم اومد اینه که من نوع fldContent توی تیبل رو text انتخاب کردم میتونه مشکل از این باشه؟

hofa_7
سه شنبه 27 اردیبهشت 1390, 21:56 عصر
myreader.read() کن عزیز

dontspeak
سه شنبه 27 اردیبهشت 1390, 22:58 عصر
myreader.read() کن عزیز
دمت گرم بخدا واسه همین دو کلمه 3 ساعته معطل بودم. اصلا یادم نبود