public void MEstudiante(ClsEstudiantes ObjEs) { //Utilizo el procedimiento almacenado con el fin de modificar un estudiante ClsBD BD = new ClsBD(); string Nombre = ObjEs.GetNombre(); int ID = ObjEs.GetNroLista(); using (SqlCommand comand = new SqlCommand("PAModificarEstudiante", BD.Conn)) { try { comand.CommandType = System.Data.CommandType.StoredProcedure; comand.Parameters.Add(new SqlParameter("@ID", ID)); comand.Parameters.Add(new SqlParameter("@Nombre", Nombre)); System.Data.DataTable DT = new System.Data.DataTable(); SqlDataAdapter DA = new SqlDataAdapter(comand); BD.Open(); DA.Fill(DT); BD.Close(); MessageBox.Show("¡" + Nombre + " modificado con éxito!"); } catch (Exception ex) { Console.Write("Error al guardar: " + ex.Message); } } }
public bool CorroborarEstudiante(ClsEstudiantes ObjEst) { //Busco si hay otro estudiante con el mismo nombre ClsBD BD = new ClsBD(); String Nom = ObjEst.GetNombre(); using (SqlCommand comand = new SqlCommand("PACorroborarEstudiante", BD.Conn)) { try { comand.CommandType = System.Data.CommandType.StoredProcedure; comand.Parameters.Add(new SqlParameter("@Nombre", Nom)); System.Data.DataTable DT = new System.Data.DataTable(); SqlDataAdapter DA = new SqlDataAdapter(comand); BD.Open(); DA.Fill(DT); BD.Close(); //Si hay un registro entonces retorno false(cuando se retorna false se da a entender que no se puede ingresar el estudiante deseado) if (DT.Rows.Count != 0) { return(false); } else { return(true); } } catch (Exception ex) { MessageBox.Show("Error:" + ex.Message); return(false); } } }