private void Txtusuario_KeyPress(object sender, KeyPressEventArgs e) { Valores.Letras(e); if (e.KeyChar == 13) { //se controlan errores try { pictureBox1.Image = Image.FromFile(@"C:\Foto\" + Txtusuario.Text + ".jpg"); pictureBox1.Visible = true; } catch (System.IO.FileNotFoundException ex) { pictureBox1.Image = global::MASTER_TUNE_UP.Properties.Resources.user2; } objconexion = new Clases.Conexión(); Conexion = new SqlConnection(objconexion.Conn()); //se abre la conexion Conexion.Open(); string query = "select * from Usuario where Us_login=@Us_login"; SqlCommand comando = new SqlCommand(query, Conexion); comando.Parameters.Clear(); comando.Parameters.AddWithValue("@Us_login", Txtusuario.Text); //asigno a leer el sqldatareader para leer el registro. SqlDataReader leer = comando.ExecuteReader(); if (leer.Read()) { txtpassword.Enabled = true; txtpassword.Focus(); pass = leer["us_password"].ToString(); nivel = leer["Us_nivel"].ToString(); if (nivel == "1") { txtnivel.Text = "administrador"; } if (nivel == "2") { txtnivel.Text = "operador"; } if (nivel == "3") { txtnivel.Text = "invitado"; } txtpassword.Enabled = true; txtpassword.Focus(); btnaccesar.Enabled = true; } else { //lo encontro MessageBox.Show("Error,usuario no registrado", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); Txtusuario.Clear(); Txtusuario.Focus(); } } }