Ejemplo n.º 1
0
        private void btnBuscar_Click(object sender, EventArgs e)
        {
            if (rbMatricula.Checked == true)
            {
                SqlConnection SqlCon = new SqlConnection();
                SqlCon.ConnectionString = Conexion.ConexionDB;

                SqlCon.Open();

                try
                {
                    if (txtBuscar.Text == string.Empty)
                    {
                        errorIcono.SetError(txtBuscar, "Ingrese la matricula");
                    }
                    else
                    {
                        this.dataListado.DataSource = NUsuario.BuscarMatricula(this.txtBuscar.Text);

                        string        SqlSelectQuery = "SELECT * FROM Usuarios WHERE matricula = " + (txtBuscar.Text);
                        SqlCommand    cmd            = new SqlCommand(SqlSelectQuery, SqlCon);
                        SqlDataReader dr             = cmd.ExecuteReader();

                        if (dr.Read())
                        {
                            txtIdUser.Text        = (dr["idUsuario"].ToString());
                            txtMatricula.Text     = (dr["matricula"].ToString());
                            txtNombre.Text        = (dr["nombre"].ToString());
                            txtApellido.Text      = (dr["apellidos"].ToString());
                            txtcbCarrera.Text     = (dr["carrera"].ToString());
                            txtcbSexo.Text        = (dr["sexo"].ToString());
                            txtcbTipoUsuario.Text = (dr["tipousuario"].ToString());
                            txtEmail.Text         = (dr["email"].ToString());
                        }
                        SqlCon.Close();

                        //
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message + ex.StackTrace);
                }
            }
            else
            {
                this.dataListado.DataSource = NUsuario.BuscarNombreCompleto(this.txtBuscar.Text);
            }
        }