I'm doing an ABC project in Windows Forms through visual studio, and after several forms I need to save the date, however, at the time of saving the connection is not successful (the connection works well with other forms that do not require the date), the code is as follows:
private void btn_Guardar_Click(object sender, EventArgs e)
{
if (alDAO.Agregar(RecuperarInformacion()) == 1)
{
MessageBox.Show("Registro Agregado");
}
else
{
MessageBox.Show("Algo salio mal");
}
//Actualiza el grid
dtg_Vista.DataSource = alDAO.Buscar();
limpiarcontroles();
}
public int Agregar(Cls_AlumnosBO alBO)
{
//se sustituyen los números por los valores de las variables
string ComandoSQL = string.Format("INSERT INTO alumno (matricula, nombre, apellido, id_div, fecha_nac)VALUES({0}, '{1}', '{2}', {3}, {4});", alBO.Matricula, alBO.Nombre, alBO.Apellido, alBO.Id_div, alBO.Fecha_nac);
return MiConexion.EjecutarComando(ComandoSQL);
}
private Cls_AlumnosBO RecuperarInformacion()
{
//Se recupera informacion del formulario
//crea un objeto de la clase productos bo
alBO = new Cls_AlumnosBO();
alBO.Matricula = Convert.ToInt32(txt_matricula.Text);
alBO.Nombre = txt_Nombre.Text;
alBO.Apellido = txt_Apellido.Text;
alBO.Fecha_nac = Convert.ToDateTime(dt_Fecha.Text);
alBO.Id_div = Convert.ToInt32(cmb_Division.SelectedValue);
return alBO;
}