所以我有一个输入表单,我在其中输入每列的值。然后在声明连接、适配器、命令和查询后,执行以下代码,不会抛出异常,也不会更新数据库:
private void BtnOk_Click(object sender, EventArgs e)
{
OleDbConnection conn = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=[MyDirectory]\Database.accdb");
conn.Open();
string query = "UPDATE [Users] SET [User]=" + txtUser.Text
+ ", [Password]=" + txtPass.Text
+ ", [IsAdmin]=" + chBAdmin.Checked.ToString()
+ " WHERE ID=" + txtID.Text + "";
OleDbDataAdapter adapter = new OleDbDataAdapter(query, conn);
OleDbCommand comm = new OleDbCommand
{
CommandType = CommandType.Text,
CommandText = query,
Connection = conn
};
try
{
comm.ExecuteNonQuery();
MessageBox.Show(query);
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
conn.Close();
}
芜湖不芜
婷婷同学_
相关分类