更新时间:2023-11-20 18:34:46
正确的更新命令 [ ^ ]是:UPDATE TableName SET FieldName = Something
WHERE AnotherFieldName = criteria
听起来像是要插入数据。如果是,则替换UPDATE
withINSERTINTO TableName(< FieldList>)
VALUES (< Values>)
protected void Button_update_Click(object sender, EventArgs e)
{
conn.Open();
string updateQuery = "update emp_details(emp_name,father_name,age,sex,dob,nationality,state,city,mobile_no,exp,qual,emp_sal,email) values(@name,@fname,@age,@sex,@dob,@nation,@state,@city,@mob,@exp,@qual,@sal,@email) ";
SqlCommand com = new SqlCommand(updateQuery, conn);
com.Parameters.AddWithValue("@name", TextBox_emp_name.Text);
com.Parameters.AddWithValue("fname", TextBox_father_name.Text);
com.Parameters.AddWithValue("@age", TextBox_Age.Text);
com.Parameters.AddWithValue("@sex", RadioButtonList_sex.Text);// is this NOTATAION correct of selecting Dropdownlist
com.Parameters.AddWithValue("@dob", TextBox_dob.Text);
com.Parameters.AddWithValue("@nation", TextBox_nationality.Text);
com.Parameters.AddWithValue("@state", TextBox_state.Text);
com.Parameters.AddWithValue("@city", TextBox_city.Text);
com.Parameters.AddWithValue("@mob", TextBox_mob.Text);
com.Parameters.AddWithValue("@exp", DropDownList_exp.Text);
com.Parameters.AddWithValue("@qual", DropDownList_qual.Text);
com.Parameters.AddWithValue("@sal", TextBox_sal.Text);
com.Parameters.AddWithValue("@email", TextBox_email.Text);
com.ExecuteNonQuery();
conn.Close();---------------->here it is showing an error"incorrect syntax near'(' "
Response.Write("Updation Succesfull");
}
The proper update command[^] is:UPDATE TableName SET FieldName = Something WHERE AnotherFieldName = criteria
Sounds like you want to insert data. If yes, then replaceUPDATE
withINSERT INTO TableName (<FieldList>) VALUES(<Values>)