namespace Lector_de_huella_y_registro { public partial class Empleados : Form { SqlConnection conn = new SqlConnection("xxxxxxxxxxxx"); public Empleados() { InitializeComponent(); } private void Limpiar() { timer1.Start(); } private void btnEditar_Click(object sender, EventArgs e) { byte[] file = null; Stream myStream = openFileDialog1.OpenFile(); using (MemoryStream ms = new MemoryStream()) { myStream.CopyTo(ms); file = ms.ToArray(); } Empleados3 empleado = new Empleados3() { IMAGEN = file }; conn.Open(); SqlCommand query = new SqlCommand($"UPDATE Empleados3 set NOMBRE = '{textBox1.Text}', IMAGEN = '{file}' WHERE ID = '{textBox2.Text}'", conn); int r = query.ExecuteNonQuery(); if (r > 0) { MessageBox.Show("Datos Actualizados"); } else { MessageBox.Show("No se lograron actualizar los datos"); } conn.Close(); Limpiar(); } private void Empleados_Load(object sender, EventArgs e) { SqlCommand command = new SqlCommand("SELECT ID, NOMBRE, IMAGEN FROM Empleados3", conn); SqlDataAdapter adapter = new SqlDataAdapter(); adapter.SelectCommand = command; DataTable tabla = new DataTable(); adapter.Fill(tabla); gvEmpleados.DataSource = tabla; } private void txtBuscarNombre_TextChanged(object sender, EventArgs e) { SqlCommand adp = new SqlCommand($"SELECT ID, NOMBRE, IMAGEN FROM Empleados3 WHERE NOMBRE = '{txtBuscarNombre.Text}'", conn); SqlDataAdapter adapter1 = new SqlDataAdapter(); adapter1.SelectCommand = adp; DataTable tabla1 = new DataTable(); adapter1.Fill(tabla1); gvEmpleados.DataSource = tabla1; } public void gvEmpleados_CellContentClick(object sender, DataGridViewCellEventArgs e) { try { textBox2.Text = gvEmpleados.CurrentRow.Cells[0].Value.ToString(); textBox1.Text = gvEmpleados.CurrentRow.Cells[1].Value.ToString(); SqlCommand command = new SqlCommand($"select IMAGEN from Empleados3 WHERE ID = '{textBox2.Text}' ", conn); SqlDataAdapter dp = new SqlDataAdapter(command); DataSet ds = new DataSet("Empleados3"); byte[] MisDatos = new byte[0]; dp.Fill(ds, "Empleados3"); DataRow myRow = ds.Tables["Empleados3"].Rows[0]; MisDatos = (byte[])myRow["IMAGEN"]; MemoryStream ms = new MemoryStream(MisDatos); pictureBox2.Image = Image.FromStream(ms); } catch { } } private void btnAñadir_Click(object sender, EventArgs e) { openFileDialog1.InitialDirectory = "c:\\"; openFileDialog1.Filter = "Archivos jpg (*jpg)|*.jpg|Archivos png(*.png)|*.png"; openFileDialog1.FilterIndex = 1; openFileDialog1.RestoreDirectory = true; if (openFileDialog1.ShowDialog() == DialogResult.OK) { textBox3.Text = openFileDialog1.FileName; pictureBox2.Image = Image.FromFile(openFileDialog1.FileName); } } private void timer1_Tick(object sender, EventArgs e) { textBox1.Text = ""; textBox2.Text = ""; textBox3.Text = ""; pictureBox2.Image = null; } } }