0
這裏是我的代碼:錯誤的更新語句
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["preconn"].ToString());
con.Open();
SqlCommand com = new SqlCommand("update slab set salbn = @salbn,basic = @basic,hra = @hra,trvl = @trvl,mdeca = @mdeca,atnd = @atnd,tote = @tote where salbn =" + DropDownList1.SelectedItem.Text, con);
com.Parameters.AddWithValue("@salbn", TextBox21.Text);
com.Parameters.AddWithValue("@basic", TextBox12.Text);
com.Parameters.AddWithValue("@hra", TextBox13.Text);
com.Parameters.AddWithValue("@trvl", TextBox15.Text);
com.Parameters.AddWithValue("@mdeca", TextBox16.Text);
com.Parameters.AddWithValue("@atnd", TextBox18.Text);
com.Parameters.AddWithValue("@tote", TextBox20.Text);
com.ExecuteNonQuery();
con.Close();
MsgBox("Updated Successfully");
}
我得到了一個錯誤:「無效的列名稱Group_A'」 我的查詢是像設置 「更新平板salbn = @salbn, basic = @ basic,hra = @ hra,trvl = @ trvl,mdeca = @ mdeca,atnd = @ atnd,tote = @tote where salbn = Group_A「
這裏Group_A是DropDownList1.SelectedItem.Text。我正在使用asp.net/C#,sql server2008。
爲什麼除了'DropDownList1.SelectedItem.Text'之外的所有東西都使用sql參數? –