هذا كود يقوم بالتعديل على جدول ولكن كل مرة اقوم بتنفيذ البرنامج يعطيني خطأ على هذا السطر
cmd.ExecuteNonQuery();
الخطأ هو :
invalid Column name 'القيمة المدخلة في النص مثل ali'
private void button2_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection("Data Source=DEVELOPMENT-PC\\SQLEXPRESS;Initial Catalog=DB_login;Integrated Security=True");
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
String queryString = "UPDATE [tb_trips] SET [id]=@id ,[reason]=@reason ,[note]=@note WHERE dName = " + textBox1.Text;
cmd.CommandText = queryString;
cmd.Connection = conn;
conn.Open();
cmd.Parameters.AddWithValue("@id", textBox2.Text);
cmd.Parameters.AddWithValue("@reason", textBox3.Text);
cmd.Parameters.AddWithValue("@note", textBox4.Text);
try
{
cmd.ExecuteNonQuery();
MessageBox.Show("Done");
}
catch (Exception e1)
{
MessageBox.Show(e1.Message);
}
finally
{
cmd.Dispose();
conn.Close();
}
}