public bool location()
{
string OUI = "OUI";
SqlConnection con = new SqlConnection(@"Data Source=WIN-218NC1F1FE2\SQLEXPRESS;Initial Catalog=projet;Integrated Security=True");
con.Open();
SqlCommand cmd = new SqlCommand("select max(id_reservation) from reservation");
cmd.Connection = con;
Int32 maxId = (Int32)cmd.ExecuteScalar();
string v = Convert.ToString(maxId);
//correct
SqlCommand q = new SqlCommand("insert into reservation(location) values('" + OUI + "') where id_reservation ='"+ maxId + "'", con);
SqlDataReader da = q.ExecuteReader();
return true ;
}
Run Code Online (Sandbox Code Playgroud)
问题在命令中:关键字'where'附近的语法不正确.救命 !!!
你不能where在insert声明中有一个条款.这就是它的全部.如果要插入,请删除该where子句.如果需要更新符合条件的记录,请不要使用insertbut update.
另外,如果您对查询结果不是真的感兴趣,请不要使用ExecuteReaderbut ExecuteNonQuery.
| 归档时间: |
|
| 查看次数: |
138 次 |
| 最近记录: |