Example #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (validacion() && valnie() && valnombre())
            {
                try
                {
                    SqlConnection getconexion = Conexion.Cnn();


                    string spinsertar = "Ingresaralumnos";
                    scomand = new SqlCommand(spinsertar, getconexion);
                    scomand.Parameters.AddWithValue("@NIE", txtNIE.Text);
                    scomand.Parameters.AddWithValue("@Nombre", txtApell.Text + "," + txtNom.Text);
                    scomand.Parameters.Add(new SqlParameter("@Fecha_Nac", SqlDbType.Date));
                    scomand.Parameters["@Fecha_Nac"].Value = dTDFechaN.Text;
                    scomand.Parameters.AddWithValue("@Telefono", txtTelefono.Text);
                    scomand.Parameters.AddWithValue("@Direccion", txtDic.Text);
                    scomand.Parameters.AddWithValue("@Responsable", txtResponsable.Text);
                    scomand.Parameters.AddWithValue("@Grado", pr.idgrado(cbGrado));
                    scomand.Parameters.AddWithValue("@Seccion", pr.idseccion(cbSeccion.Text));

                    scomand.CommandType = CommandType.StoredProcedure;
                    scomand.ExecuteNonQuery();
                    getconexion.Close();
                    MessageBox.Show("Agregado con exito", "REGISTRO", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    txtNIE.Clear();
                    txtNom.Clear();
                    txtApell.Clear();
                    dTDFechaN.ResetText();
                    txtTelefono.Clear();
                    txtDic.Clear();
                    txtResponsable.Clear();
                    cbGrado.Text   = "";
                    cbSeccion.Text = "";
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error" + ex, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else
            {
                MessageBox.Show("Error en registro", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtNIE.Clear();
                txtNom.Clear();
                txtApell.Clear();
                dTDFechaN.ResetText();
                txtTelefono.Clear();
                txtDic.Clear();
                txtResponsable.Clear();
                cbGrado.Text   = "";
                cbSeccion.Text = "";
            }
        }