I have this code made so far where I apply the SP "InsertEmployee", it adds records to the BD:
var Insertar_NuevoEmpleado = _empleados.InsertarEmpleado(txtcedula.Text, txtnombres.Text, txtapellidos.Text, txtcargo.Text, txtdepartamento.Text, Convert.ToDecimal(txtsalario.Text), txtUrl.Text);
What I try to do is a search with another SP where I bring the records corresponding to the parameter sent. It happens that, the form has a PictureBox, by means of which an image is stored in the database ( itself the route where the image is stored is stored ) and this is the search code:
private void btnBuscarEmpleado_Click(object sender, EventArgs e)
{
btnBuscarEmpleado.Image = imageList1.Images[0];
if (string.IsNullOrEmpty(txtBuscarCedula.Text))
{
MessageBox.Show("Ingrese un número de cédula valido", "Buscar Empleado", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
return;
}
empresaEntities _empleados = new empresaEntities();
{
nomina _trabajador = new nomina();
var BuscarEmpleado = _empleados.BuscarEmpleados(txtBuscarCedula.Text).ToList();
if (BuscarEmpleado.Count() > 0)
{
MessageBox.Show("El empleado existe en la base de datos.", "¡ATENCIÓN!", MessageBoxButtons.OK, MessageBoxIcon.Stop);
txtcedula.Text = BuscarEmpleado.FirstOrDefault().cedula.ToString("N0");
txtnombres.Text = BuscarEmpleado.FirstOrDefault().nombres;
txtapellidos.Text = BuscarEmpleado.FirstOrDefault().apellidos;
txtcargo.Text = BuscarEmpleado.FirstOrDefault().cargo;
txtdepartamento.Text = BuscarEmpleado.FirstOrDefault().departamento;
txtsalario.Text = BuscarEmpleado.FirstOrDefault().salario.ToString("N2");
txtUrl.Text = BuscarEmpleado.FirstOrDefault().UrlFoto;
pictureBox1.Image = Image.FromFile(BuscarImagen.FileName); **<- AQUI me marca el ERROR**
}
else
{
MessageBox.Show("El número de cédula no existe en la base de datos. ¿Desea ingresar uno nuevo?", "Confirmar", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
}
}
}
It is evident that the pictureBox has no code. The question is, how do I make the corresponding call for this object, where it shows me the image to which the parameter sent by the SP is associated.
I comment:
The SP obviously works for me without the Image parameter, but the idea is to bring the records and in turn to show the image too.
For more info:
I search for the image using the following code and store the image path:
private void btnBuscarFoto_Click(object sender, EventArgs e)
{
OpenFileDialog BuscarImagen = new OpenFileDialog();
BuscarImagen.Filter = "Archivo PNG|*.png";
if (BuscarImagen.ShowDialog() == DialogResult.OK)
{
pictureBox1.Image = Image.FromFile(BuscarImagen.FileName);
}
txtUrl.Text = BuscarImagen.FileName;
}
In addition to this, when I do the Debugg of the application, I mark error in this line when trying to do the search.
pictureBox1.Image = Image.FromFile(BuscarImagen.FileName);
Indicating the following: Severity Code Description Project File Line Error CS1061 'List' does not contain a definition for 'FileName' and no extension method 'FileName' accepting a first argument of type 'List' could be found ( Are you missing a using directive or an assembly reference?)
If you have opinions or answers about it, examples in EF.
Thank you!