private void button6_Click(object sender, EventArgs e)
{
xcon.Open();
SqlDataAdapter xadapter = new SqlDataAdapter();
SqlCommand command = new SqlCommand(
"UPDATE dbo.SysX SET fp = @fp, sd = @sd, sf= @sf" +
"WHERE id = 2019", xcon);
command.Parameters.Add("@fp", SqlDbType.Int, 5, textBox1.Text);
command.Parameters.Add("@sd", SqlDbType.Int, 40, textBox2.Text);
command.Parameters.Add("@sf", SqlDbType.Int, 40, textBox3.Text);
xadapter.UpdateCommand = command;
xcon.Close();
}
希望点击按钮更新id = 2019的数据库内的信息。没有发生任何错误...我没有使用数据表只是更新
我究竟做错了什么?
1)您错过了执行查询2)转换为正确的类型3)此外,我也将ID作为参数。
private void button6_Click(object sender, EventArgs e)
{
xcon.Open();
SqlDataAdapter xadapter = new SqlDataAdapter();
SqlCommand command = new SqlCommand(
@"UPDATE dbo.SysX SET fp = @fp, sd = @sd, sf= @sf
WHERE id = @id", xcon);
command.Parameters.Add("@fp", SqlDbType.Int, Convert.ToInt32(textBox1.Text));
command.Parameters.Add("@sd", SqlDbType.Int, Convert.ToInt32(textBox2.Text));
command.Parameters.Add("@sf", SqlDbType.Int, Convert.ToInt32(textBox3.Text));
command.Parameters.Add("@Id", SqlDbType.Int, 2019);
// next command !!!
command.ExecuteNonQuery();
xadapter.UpdateCommand = command;
xcon.Close();
}