So, I have my update and its giving me this error on a string. I already tried using the concatenation way without params, I've tryed changing the params order and making the verification for null, still its returning errors.
For the ones asking. The error its in the title "Must declare the scalar variable "@Apellido"."
This is the entire code:
using (OleDbConnection connection = new OleDbConnection(connectionString))
{
OleDbCommand command = new OleDbCommand();
OleDbTransaction transaction = null;
// Set the Connection to the new OleDbConnection.
command.Connection = connection;
// Open the connection and execute the transaction.
try
{
connection.Open();
command.CommandText = "UPDATE Asociados SET Apellido=@Apellido, Nombre=@Nombre, FechaNacimiento=@FechaNacimiento, Comentarios=@Comentarios, DNI=@DNI, ParcelaID=@ParcelaID, FechaIngreso=@FechaIngreso, Nacionalidad=@Nacionalidad, EstadoCivil=@EstadoCivil, Profesion=@Profesion, DomicilioComercial=@DomicilioComercial, TelefonoComercial=@TelefonoComercial, Celular=@Celular, Email=@Email, Patente1=@Patente1, Patente2=@Patente2, Patente3=@Patente3, Domicilio=@Domicilio, Telefono=@Telefono, Localidad=@Localidad, CodigoPostal=@CodigoPostal, Referente=@Referente, Saldo=@Saldo, FechaBaja=@FechaBaja WHERE ID=@ID";
command.Parameters.AddWithValue("@ID", ((object)AsociadoModificado.ID) ?? DBNull.Value);
command.Parameters.AddWithValue("@Apellido", AsociadoModificado.Apellido.ToString());
command.Parameters.AddWithValue("@Nombre",AsociadoModificado.Nombre.ToString());
command.Parameters.AddWithValue("@FechaNacimiento",Convert.ToDateTime(AsociadoModificado.FechaNacimiento).Date);
command.Parameters.AddWithValue("@Comentarios", AsociadoModificado.Comentarios.ToString());
command.Parameters.AddWithValue("@DNI", ((object)AsociadoModificado.DNI) ?? DBNull.Value);
command.Parameters.AddWithValue("@ParcelaID", ((object)AsociadoModificado.ParcelaID) ?? DBNull.Value);
command.Parameters.AddWithValue("@FechaIngreso", ((object)Convert.ToDateTime(AsociadoModificado.FechaIngreso).Date) ?? DBNull.Value);
command.Parameters.AddWithValue("@Nacionalidad", ((object)AsociadoModificado.Nacionalidad) ?? DBNull.Value);
command.Parameters.AddWithValue("@EstadoCivil", ((object)AsociadoModificado.EstadoCivil) ?? DBNull.Value);
command.Parameters.AddWithValue("@Profesion", ((object)AsociadoModificado.Profesion) ?? DBNull.Value);
command.Parameters.AddWithValue("@DomicilioComercial", ((object)AsociadoModificado.DomicilioComercial) ?? DBNull.Value);
command.Parameters.AddWithValue("@TelefonoComercial", ((object)AsociadoModificado.TelefonoComercial) ?? DBNull.Value);
command.Parameters.AddWithValue("@Celular", ((object)AsociadoModificado.Celular) ?? DBNull.Value);
command.Parameters.AddWithValue("@Email", ((object)AsociadoModificado.Email) ?? DBNull.Value);
command.Parameters.AddWithValue("@Patente1", ((object)AsociadoModificado.Patente1) ?? DBNull.Value);
command.Parameters.AddWithValue("@Patente2", ((object)AsociadoModificado.Patente2) ?? DBNull.Value);
command.Parameters.AddWithValue("@Patente3", ((object)AsociadoModificado.Patente3) ?? DBNull.Value);
command.Parameters.AddWithValue("@Domicilio", ((object)AsociadoModificado.Domicilio) ?? DBNull.Value);
command.Parameters.AddWithValue("@Telefono", ((object)AsociadoModificado.Telefono) ?? DBNull.Value);
command.Parameters.AddWithValue("@Localidad", ((object)AsociadoModificado.Localidad) ?? DBNull.Value);
command.Parameters.AddWithValue("@CodigoPostal", ((object)AsociadoModificado.CodigoPostal) ?? DBNull.Value);
command.Parameters.AddWithValue("@Referente", ((object)AsociadoModificado.Referente) ?? DBNull.Value);
command.Parameters.AddWithValue("@Saldo", ((object)AsociadoModificado.Saldo) ?? DBNull.Value);
command.Parameters.AddWithValue("@FechaBaja", ((object)AsociadoModificado.FechaBaja) ?? DBNull.Value);
command.ExecuteNonQuery();
connection.Close();
}
catch(Exception e)
{
}
}