我想用另一个值更新整个选定的相同列...
继承人我试过的代码,显然它不起作用(错误是DB没有变化)
OleDbConnection con = new OleDbConnection();
con.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Rock.accdb";
OleDbCommand cmd = new OleDbCommand();
cmd.Connection = con;
con.Open();
cmd.CommandText = "UPDATE profile SET [year]=@1 WHERE [year]=@2";
cmd.Parameters.AddWithValue("@1", comboBox1.Text);
cmd.Parameters.AddWithValue("@2", comboBox2.Text);
cmd.ExecuteNonQuery();
con.Close();
label4.Text = "Updated successfully";
label4.ForeColor = Color.Green;
请尊重,如果你们有任何疑问只是评论......
答案 0 :(得分:0)
尝试:
cmd.CommandText = "UPDATE profile SET [year]=? WHERE [year]=?"
并更新参数(参数必须按照查询中的'?'的顺序添加)
cmd.Parameters.AddWithValue("?", comboBox1.Text);
cmd.Parameters.AddWithValue("?", comboBox2.Text);