【发布时间】:2016-10-04 08:52:59
【问题描述】:
如何通过sql查询更新数据库中的bool
以下是我拥有的代码,但我不确定如何实现该复选框。 感谢您的帮助。
我已更新代码以消除 sql 注入问题。
con.Open();
OleDbCommand cmd = new OleDbCommand(String.Concat("Select * From ", comboBox1.Text), con);
cmd.CommandType = CommandType.Text;
string tableName = comboBox1.Text.ToString();
cmd.CommandText = @"UPDATE [" + tableName + "] SET"
+"People_Call_Status = @People_Call_Status,"
+"Research_Date=@Research_Date,"
+ "tblCompanies_Area_Dialling_Code = @tblCompanies_Area_Dialling_Code,"
+ "Work_Number = @Work_Number,"
+ "building_Address = @building_Address,"
+ "[Street Address] = @[Street Address],"
+ "suburb = @suburb,"
+ "city = @city,"
+ "res_Code = @res_Code,"
+ "industry_Vertical_ID = @industry_Vertical_ID,"
+ "pO_Box = @pO_Box,"
+ "post_Office = @post_Office,"
+ "postal_Code = @postal_Code,"
+ "country_ID = @country_ID,"
+ "province_ID = @province_ID," //this line
+ "prospect = @prospect"
+ "WHERE Company_ID = @Company_ID ";
cmd.Parameters.AddWithValue("@People_Call_Status", Status_textBox1.Text);
cmd.Parameters.AddWithValue("@Research_Date", Date_textBox.Text);
cmd.Parameters.AddWithValue("@Company_Name", company_NameTextBox.Text);
cmd.Parameters.AddWithValue("@tblCompanies_Area_Dialling_Code", tblCompanies_Area_Dialling_CodeTextBox.Text);
cmd.Parameters.AddWithValue("@Work_Number", work_NumberTextBox.Text);
cmd.Parameters.AddWithValue("@building_Address", building_AddressTextBox.Text);
cmd.Parameters.AddWithValue("@[Street Address]", street_AddressTextBox.Text);
cmd.Parameters.AddWithValue("@suburb", suburbTextBox.Text);
cmd.Parameters.AddWithValue("@city", cityTextBox.Text);
cmd.Parameters.AddWithValue("@res_Code", res_CodeTextBox.Text);
cmd.Parameters.AddWithValue("@industry_Vertical_ID", industry_Vertical_IDTextBox.Text);
cmd.Parameters.AddWithValue("@pO_Box", pO_BoxTextBox.Text);
cmd.Parameters.AddWithValue("@post_Office", post_OfficeTextBox.Text);
cmd.Parameters.AddWithValue("@postal_Code", postal_CodeTextBox.Text);
cmd.Parameters.AddWithValue("@country_ID", country_IDTextBox.Text);
cmd.Parameters.AddWithValue("@province_ID", province_IDTextBox.Text);
cmd.Parameters.AddWithValue("@prospect", prospectCheckBox.Checked);
cmd.Parameters.AddWithValue("@Company_ID", company_IDTextBox.Text);
cmd.ExecuteNonQuery();
{
MessageBox.Show("Update Success!");
con.Close();
}
【问题讨论】:
-
1.您的代码容易受到 sql 注入的攻击。 2 “不工作”不是对您所面临问题的有效描述,请通过仔细描述您想要的内容来帮助我们帮助您...
-
Checked属性是bool。您的prospect列也是布尔类型还是位类型?如果是这样,请尝试在将 Checked 属性添加到语句之前和之后删除 '。正如@Adimeus 所说,您的代码容易受到 SQL 注入的影响,请尝试使用参数。 -
所以你没有办法帮助我如何更新数据库中的布尔值?