如何通过单击按钮
从数据库更新表格protected void btnFinish_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
con.Open();
string insCmd = "UPDATE Orders SET finish = 1 WHERE finish IS NULL";
SqlCommand addOrder = new SqlCommand(insCmd, con);
addOrder.Parameters.AddWithValue("finish", 1);
con.Close();
}
请帮忙
答案 0 :(得分:2)
您需要执行命令:
SqlCommand addOrder = new SqlCommand(insCmd, con);
addOrder.Parameters.AddWithValue("@finish", 1);
addOrder.ExecuteNonQuery();
答案 1 :(得分:2)
您必须使用以下代码运行Sql语句:
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
con.Open();
string insCmd = "UPDATE Orders SET finish = 1 WHERE finish IS NULL";
SqlCommand addOrder = new SqlCommand(insCmd, con);
addOrder.Parameters.AddWithValue("finish", 1);
addOrder.ExecuteNonQuery();
con.Close();