我一直在尝试在DataGridView中更新,但它总是返回这个
没有为一个或多个必需参数指定值
这是我的代码
private void btnAlterar_Click(object sender, EventArgs e)
{
try
{
string strincon = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\flavi\Desktop\Pet&Shop.2\PetShop\TelaAbertura\bin\Debug\DatabasePS.mdb;Persist Security Info=True";
OleDbConnection con = new OleDbConnection(strincon);
con.Open();
String comando = "UPDATE Funcionario SET Nome= '" + txtNome.Text + "' , Login= '" + txtLogin.Text + "' , Senha= '" + txtSenha.Text + "', Email= '" + txtEmail.Text + "' , Cargo= '" + txtCargo.Text + "' WHERE Codigo =" + codigo;
OleDbCommand cmd = new OleDbCommand(comando, con);
cmd.ExecuteNonQuery();
MessageBox.Show("Dados Alterados Com Sucesso!");
txtCargo.Clear();
txtEmail.Clear();
txtLogin.Clear();
txtNome.Clear();
txtSenha.Clear();
con.Close();
}
catch (Exception erro)
{
MessageBox.Show(erro.Message);
}
}
发布于 2018-06-04 06:38:08
您需要在字段名称上添加括号,因为某些字段名称在访问时可能是关键字。按如下方式更改您的查询:
String comando = "UPDATE [Funcionario] SET [Nome]= '" + txtNome.Text + "' , [Login]= '" + txtLogin.Text + "' , [Senha]= '" + txtSenha.Text + "', [Email]= '" + txtEmail.Text + "' , [Cargo]= '" + txtCargo.Text + "' WHERE [Codigo] =" + codigo;
https://stackoverflow.com/questions/50671494
复制相似问题