C# Access数据库c中的更新查询出错#
我的代码中有一个错误。它给了我一个OLEDBEException(一个或多个必需的参数没有给出值),希望有人能给我指路 以下是我的部分代码:C# Access数据库c中的更新查询出错#,c#,sql-update,oledb,oledbexception,C#,Sql Update,Oledb,Oledbexception,我的代码中有一个错误。它给了我一个OLEDBEException(一个或多个必需的参数没有给出值),希望有人能给我指路 以下是我的部分代码: public void buttonEditar_Click(object sender, EventArgs e) { OleDbConnection connection = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Gera\Docu
public void buttonEditar_Click(object sender, EventArgs e)
{
OleDbConnection connection = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Gera\Documents\Visual Studio 2012\Projects\RichyAutoCenter\RichyAutoCenter\bin\Debug\Camionetas.accdb;");
string query = "UPDATE [Camionetas] SET VIN = ?, Marca = ?, Modelo = ?, Año = ?, Rentada = ?, FechaRenta = ?, FechaEntrega = ?, DiasAtrasados = ?, FechaAceite = ?, FechaCambio = ?, Obervaciones = ?, PersonaRentada = ? WHERE ID = ?";
int ID = int.Parse(numero);
string Vin = textBoxVin.Text;
string Marca = textBoxMarca.Text;
string Modelo = textBoxModelo.Text;
string Ano = textBoxAno.Text;
Boolean Rentada = checkBoxRentada.Checked;
string FechaRenta = dateTimePickerFechaRenta.Value.ToShortDateString();
string FechaEntrega = dateTimePickerFechaEntrega.Value.ToShortDateString();
int DiasAtrasados = int.Parse(textBoxDiasAtrasados.Text);
string FechaAceite = dateTimePickerFechaAceite.Value.ToShortDateString();
string FechaCambio = dateTimePickerFechaCambio.Value.ToShortDateString();
string Observaciones = textBoxObservaciones.Text;
string PersonaRentada = comboBoxPersonaRenta.Text;
OleDbCommand command = new OleDbCommand(query, connection);
command.CommandType = CommandType.Text;
command.Parameters.AddWithValue("?",Vin);
command.Parameters.AddWithValue("?",Marca);
command.Parameters.AddWithValue("?",Modelo);
command.Parameters.AddWithValue("?",Ano);
command.Parameters.AddWithValue("?",Rentada);
command.Parameters.AddWithValue("?",FechaRenta);
command.Parameters.AddWithValue("?",FechaEntrega);
command.Parameters.AddWithValue("?",DiasAtrasados);
command.Parameters.AddWithValue("?",FechaAceite);
command.Parameters.AddWithValue("?",FechaCambio);
command.Parameters.AddWithValue("?",Observaciones);
command.Parameters.AddWithValue("?",PersonaRentada);
command.Parameters.AddWithValue("?",ID);
connection.Open();
command.ExecuteNonQuery(); // No value given for one or more required parameters error
connection.Close();
}
替换您的所有
command.Parameters.AddWithValue(“?”,ID)代码>带有常规:命令.参数.添加(ID)代码>
或者使用不同的名称而不是?
,请查看