Hello, good morning to all, along with saying hello I wanted to see if you could guide me a bit: I have a project in layers c # and mysql, I have to save a date from a datetimepicker to a datetime field of mysql, but it shows me these errors : on my data layer I have a method to insert data:
public datosProfesional(int idProfesional, int idLogin, string rut_profesional, string nombres_profesional, string ape_pat, string ape_mat, MySqlDateTime fecha_nacimiento, string sexo, string direccion, int telefono, string email, string profesion, string especialidad, string codigo_autorizacion, string observaciones, string textoBusqueda)
{
this.IdProfesional = idProfesional; //AUTOINCREMENTAL
this.IdLogin = IdLogin;
this.Rut_profesional = rut_profesional;
this.Nombres_profesional = nombres_profesional;
this.Ape_pat = ape_pat;
this.Ape_mat = ape_mat;
this.Fecha_nacimiento = fecha_nacimiento;
this.Sexo = sexo;
this.Direccion = direccion;
this.Telefono = telefono;
this.Email = email;
this.Profesion = profesion;
this.Especialidad = especialidad;
this.Codigo_autorizacion = codigo_autorizacion;
this.Observaciones = observaciones;
this.TextoBusqueda = textoBusqueda;
}
//METODO INSERTAR
public string insertarProfesional(datosProfesional profesional)
{
string respuesta = "";
MySqlConnection con = new MySqlConnection();
try
{
//CADENA DE CONEXION
con.ConnectionString = conexion.cadenaConexion;
//ABRIMOS LA CONEXION
con.Open();
//COMANDO PARA EJECUTAR CONSULTA
MySqlCommand cmd = new MySqlCommand();
cmd.Connection = con;
//LLAMAMOS A LA CONSULTA O PROCEDIMIENTO ALMACENADO
cmd.CommandText = "spInsertarProfesional";
cmd.CommandType = CommandType.StoredProcedure;
//DECLARAMOS LOS PARAMETROS QUE SON IGUALES A LOS QUE TENEMOS EN EL SP
MySqlParameter parIdProfesional = new MySqlParameter();
parIdProfesional.ParameterName = "@idprofesional";
parIdProfesional.MySqlDbType = MySqlDbType.Int32;
parIdProfesional.Direction = ParameterDirection.Output;
cmd.Parameters.Add(parIdProfesional);
//14 VARIABLES
MySqlParameter parLogin = new MySqlParameter();
parLogin.ParameterName = "@idlogin";
parLogin.MySqlDbType = MySqlDbType.Int32;
parLogin.Value = profesional.IdLogin;
parLogin.Direction = ParameterDirection.Input;
cmd.Parameters.Add(parLogin);
MySqlParameter parRutProf = new MySqlParameter();
parRutProf.ParameterName = "@rutprofesional";
parRutProf.MySqlDbType = MySqlDbType.VarChar;
parRutProf.Direction = ParameterDirection.Input;
parRutProf.Size = 25;
parRutProf.Value = profesional.Rut_profesional;
cmd.Parameters.Add(parRutProf);
MySqlParameter parNombreProf = new MySqlParameter();
parNombreProf.ParameterName = "@nombres";
parNombreProf.MySqlDbType = MySqlDbType.VarChar;
parNombreProf.Direction = ParameterDirection.Input;
parNombreProf.Size = 100;
parNombreProf.Value = profesional.Nombres_profesional;
cmd.Parameters.Add(parNombreProf);
MySqlParameter parApePat = new MySqlParameter();
parApePat.ParameterName = "@apepat";
parApePat.MySqlDbType = MySqlDbType.VarChar;
parApePat.Direction = ParameterDirection.Input;
parApePat.Size = 50;
parApePat.Value = profesional.Ape_pat;
cmd.Parameters.Add(parApePat);
MySqlParameter parApeMat = new MySqlParameter();
parApeMat.ParameterName = "@apemat";
parApeMat.MySqlDbType = MySqlDbType.VarChar;
parApeMat.Direction = ParameterDirection.Input;
parApeMat.Size = 50;
parApeMat.Value = profesional.Ape_mat;
cmd.Parameters.Add(parApeMat);
MySqlParameter parFechaNac = new MySqlParameter();
parFechaNac.ParameterName = "@fecha_nac";
parFechaNac.MySqlDbType = MySqlDbType.DateTime;
parFechaNac.Direction = ParameterDirection.Input;
parFechaNac.Value = profesional.Fecha_nacimiento;
cmd.Parameters.Add(parFechaNac);
MySqlParameter parSexo = new MySqlParameter();
parSexo.ParameterName = "@sexo";
parSexo.MySqlDbType = MySqlDbType.VarChar;
parSexo.Size = 45;
parSexo.Value = profesional.Sexo;
parSexo.Direction = ParameterDirection.Input;
cmd.Parameters.Add(parSexo);
MySqlParameter parDireccion = new MySqlParameter();
parDireccion.ParameterName = "@direccion";
parDireccion.MySqlDbType = MySqlDbType.VarChar;
parDireccion.Size = 150;
parDireccion.Value = profesional.Direccion;
parDireccion.Direction = ParameterDirection.Input;
cmd.Parameters.Add(parDireccion);
MySqlParameter parEmail = new MySqlParameter();
parEmail.ParameterName = "@email";
parEmail.MySqlDbType = MySqlDbType.VarChar;
parEmail.Size = 150;
parEmail.Value = profesional.Email;
parEmail.Direction = ParameterDirection.Input;
cmd.Parameters.Add(parEmail);
MySqlParameter parFono = new MySqlParameter();
parFono.ParameterName = "@telefono";
parFono.MySqlDbType = MySqlDbType.Int32;
parFono.Size = 9;
parFono.Value = profesional.Telefono;
parFono.Direction = ParameterDirection.Input;
cmd.Parameters.Add(parFono);
MySqlParameter parProfesion = new MySqlParameter();
parProfesion.ParameterName = "@profesion";
parProfesion.MySqlDbType = MySqlDbType.VarChar;
parProfesion.Size = 150;
parProfesion.Value = profesional.Profesion;
parProfesion.Direction = ParameterDirection.Input;
cmd.Parameters.Add(parProfesion);
MySqlParameter parEspecialdiad = new MySqlParameter();
parEspecialdiad.ParameterName = "@especialidad";
parEspecialdiad.MySqlDbType = MySqlDbType.VarChar;
parEspecialdiad.Size = 150;
parEspecialdiad.Value = profesional.Especialidad;
parEspecialdiad.Direction = ParameterDirection.Input;
cmd.Parameters.Add(parEspecialdiad);
MySqlParameter parCodAutoriz = new MySqlParameter();
parCodAutoriz.ParameterName = "@codigo_aut";
parCodAutoriz.MySqlDbType = MySqlDbType.VarChar;
parCodAutoriz.Size = 45;
parCodAutoriz.Value = profesional.Codigo_autorizacion;
parCodAutoriz.Direction = ParameterDirection.Input;
cmd.Parameters.Add(parCodAutoriz);
MySqlParameter parObservaciones = new MySqlParameter();
parObservaciones.ParameterName = "@observaciones";
parObservaciones.MySqlDbType = MySqlDbType.MediumText;
parObservaciones.Value = profesional.Observaciones;
parObservaciones.Direction = ParameterDirection.Input;
cmd.Parameters.Add(parObservaciones);
//EJECUCION DEL COMANDO
respuesta = cmd.ExecuteNonQuery() == 1 ? "ok" : "no se pudo";
}
catch (Exception ex)
{
respuesta = ex.Message;
}
//CIERRE DE CONEXION
finally
{
if (con.State == ConnectionState.Open) con.Close();
}
//RETORNAMOS LA VARIABLE DEL METODO
return respuesta;
}
this is the code of my business layer:
//INSERTAR
public static string insertarProfesional(
int idLogin,
string rut_profesional,
string nombres_profesional,
string ape_pat,
string ape_mat,
MySqlDateTime fecha_nacimiento,
string sexo,
string direccion,
int telefono,
string email,
string profesion,
string especialidad,
string codigo_autorizacion,
string observaciones)
{
datosProfesional obj = new datosProfesional();
obj.IdLogin = idLogin;
obj.Rut_profesional = rut_profesional;
obj.Nombres_profesional = nombres_profesional;
obj.Ape_pat = ape_pat;
obj.Ape_mat = ape_mat;
obj.Fecha_nacimiento = fecha_nacimiento;
obj.Sexo = sexo;
obj.Direccion = direccion;
obj.Telefono = telefono;
obj.Email = email;
obj.Profesion = profesion;
obj.Especialidad = especialidad;
obj.Codigo_autorizacion = codigo_autorizacion;
obj.Observaciones = observaciones;
return obj.insertarProfesional(obj);
}
and the error I have in the code of my form:
if (this.isNuevo)
{
respuesta = negociosProfesional.insertarProfesional(
Convert.ToInt32(this.txtId.Text),
//convert.toInt32(this.txtId.Text),
this.txtDocumento.Text,
this.txtNombre.Text,
this.txtApePat.Text,
this.txtApeMat.Text,
dtpFechaNacimiento.Value,
this.cmbSexo.Text,
this.txtDireccion.Text,
Convert.ToInt32(this.txtFono.Text),
this.txtEmail.Text,
this.txtProfesion.Text,
this.txtEspecialidad.Text,
this.txtObservaciones.Text,
this.txtEspecialidad.Text
);
}
else
{
//respuesta = negociosProfesional.editarProfesional(this.txtDocumento.Text.Trim());
}
}
Greetings to all and I thank you already