همونطور که گفتم این کد هم کار نکرد و ارور دقیقا همون ارور کد قبلی بود . راه دیگه ای به ذهنم نرسید جز اینکه بزرگترین جنایت دنیای برنامه نویسی رو مرتکب بشم که باعث شد کد باتونم به این شکل در بیاد :
private void button_sabtekarbar_Click(object sender, EventArgs e)
{
MemoryStream mStream = new MemoryStream();
pictureBox1.Image.Save(mStream, ImageFormat.Gif);
if (textBox4_pass.Text == textBox7_confPass.Text)
{
if (isUpdateForm == false)
{
//byte[] pic = ReadFile(picPath);
rwd.daInsert("INSERT INTO users ([name] ,lname, semat ,username, pass, sabtkonande,image)"
+ "values('" + textBox1_name.Text + "','"
+ textBox2_lname.Text + "','"
+ textBox5_job.Text + "','"
+ textBox3_uname.Text + "','"
+ textBox4_pass.Text + "','"
+ textBox6_sabtkonande.Text + "','"
+ mStream.GetBuffer() + "')");
MessageBox.Show("کاربر مورد نظر با موفقیت ثبت شد.", "", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
SqlConnection con = new SqlConnection();
SqlCommand cmd = new SqlCommand();
con.ConnectionString = "server=(local)\\sqlexpress;" +
"initial catalog=University;" +
"user id=Administrator;integrated security=SSPI;";
cmd.Connection = con;
cmd.CommandText = "update users set [name]=@name, lname=@lname, semat=@semat"
+ ", pass=@pass , sabtkonande=@sabtkonande , image=@image";
cmd.Parameters.AddWithValue("@name", textBox1_name.Text);
cmd.Parameters.AddWithValue("@lname", textBox2_lname.Text);
cmd.Parameters.AddWithValue("@semat", textBox5_job.Text);
cmd.Parameters.AddWithValue("@pass", textBox4_pass.Text);
cmd.Parameters.AddWithValue("@sabtkonande", textBox6_sabtkonande.Text);
cmd.Parameters.AddWithValue("@image", mStream.GetBuffer());
con.Open();
cmd.ExecuteNonQuery();
con.Close();
MessageBox.Show("اطلاعات وارد شده با موفقیت تغییر یافت.", "", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
else
MessageBox.Show("رموز وارد شده یکسان نیستند" , "خطا", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
میدونم بد آموزی داره ولی چاره ای جز خط زدن صورت مسأله نبود.
به نظر خودم دلیل اون ارور شاید این بود که نباید مقادیر کنترل ها به صورت پارامتر به تابع اون کلاس فرستاده میشدن . احتمالا وقتی مقادیر اونجا میرفت خالی میشد .