public string Insertar(classProfesores mt) { SqlCommand cmd = new SqlCommand("spo_InsertarProfesores", conn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@Id", mt.Id); cmd.Parameters.AddWithValue("@nombre", mt.nombre); cmd.Parameters.AddWithValue("@apellidos", mt.apellidos); cmd.Parameters.AddWithValue("@fechaReg", mt.fechaReg); cmd.Parameters.AddWithValue("@Usr", mt.Usr); cmd.Parameters.AddWithValue("@accion", 1); try { if (conn.State == ConnectionState.Closed) conn.Open(); cmd.ExecuteNonQuery(); } catch (Exception) { return "Se ha producido un error..."; } finally { if (conn.State == ConnectionState.Open) conn.Close(); } return "Operacion realizada exitosamente..."; }
protected void btnGuardar_Click(object sender, EventArgs e) { if (txtNombre.Text.Trim().Length == 0 || txtApellidos.Text.Trim().Length == 0) { //Msg.Text = "Datos incompletos..."; return; } classProfesores mt = new classProfesores(); mt.Id = txtId.Text.Trim().Length == 0 ? 0 : Convert.ToInt32(txtId.Text); mt.nombre = mt.nombre = txtNombre.Text; mt.apellidos = txtApellidos.Text; mt.fechaReg = DateTime.Now; mt.Usr = "******"; string result = Insertar(mt); //Msg.Text = result; fillGV(); txtId.Text = ""; txtNombre.Text = ""; txtApellidos.Text = ""; txtApellidos.Focus(); }