public static int Agregar(estudiante Estu) { int retorno = 0; MySqlCommand comando = new MySqlCommand(string.Format("Insert into estudiantes (codEst, nombreEst, semestreEst, carreraEst, domicilio, telefonoEst) values ('{0}','{1}','{2}', '{3}', '{4}', '{5}')", Estu.codEstu, Estu.nombreEstu, Estu.semestreEstu, Estu.carreraEstu, Estu.domicilioEstu, Estu.telefonoEstu), conexion.ObtenerConexion()); retorno = comando.ExecuteNonQuery(); return(retorno); }
private void bto_registrar_Click(object sender, EventArgs e) { /* string titu = (txt_nomb.Text); * string cog = (txt_codigo.Text); * string edi = (txt_carr.Text); * string edito = (txt_semestre.Text); * int aut = int.Parse(txt_telefono.Text); * string carre = (txt_domicilio.Text); * * lis_estudiante.crear_lista(titu, cog, edi, edito, aut, carre); * //LIMPIAR * txt_nomb.Clear(); * txt_codigo.Text = ""; * txt_carr.Text = ""; * txt_semestre.Clear(); * txt_telefono.Clear(); * txt_domicilio.Clear(); * * // lst_libro.Items.Clear(); * // * //TXT_CODIGO_MOVIL.Focus();*/ estudiante pEstidiante = new estudiante(); pEstidiante.codEstu = txt_codigo.Text.Trim(); pEstidiante.nombreEstu = txt_nomb.Text.Trim(); pEstidiante.semestreEstu = txt_semestre.Text.Trim(); pEstidiante.carreraEstu = txt_carr.Text.Trim(); pEstidiante.domicilioEstu = txt_domicilio.Text.Trim(); pEstidiante.telefonoEstu = txt_telefono.Text.Trim(); int resultado = estudianteBD.Agregar(pEstidiante); if (resultado > 0) { MessageBox.Show(" Registrado Con Exito!!", "Guardado", MessageBoxButtons.OK, MessageBoxIcon.Information); Limpiar(); } else { MessageBox.Show("No se pudo Registrar ", "Fallo!!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } }
public static List <estudiante> Buscar() { List <estudiante> _lista = new List <estudiante>(); MySqlCommand _comando = new MySqlCommand(String.Format( "SELECT codEst, nombreEst, semestreEst, carreraEst, domicilioEst,telefonoEst FROM estudiantes"), estudiante.ObtenerConexion()); MySqlDataReader _reader = _comando.ExecuteReader(); while (_reader.Read()) { estudiante pEstu = new estudiante(); pEstu.codEstu = _reader.GetString(0); pEstu.nombreEstu = _reader.GetString(1); pEstu.semestreEstu = _reader.GetString(2); pEstu.carreraEstu = _reader.GetString(3); pEstu.domicilioEstu = _reader.GetString(4); pEstu.telefonoEstu = _reader.GetString(5); } return(_lista); }