Good evening, I would like you to help me. I'm doing an image insert with SQL SERVER and C #. These are the fields of my table:
CREATE TABLE [dbo].[alumno]( [Alu_IMAGEN] [VARCHAR](250) NULL ) ON [PRIMARY]
This is my stored procedure called Registrar_Alumno
ALTER PROCEDURE [dbo].[Registrar_Alumno] @aluimagen VARCHAR(200) @opc int AS BEGIN IF @opc=1 begin INSERT INTO dbo.alumno ( alu_Imagen ) VALUES ( @aluimagen ) SELECT '1' end END
As I said I have done in 3 layers I am new to this Methodology and I would like you to help me as I can not insert AN IMAGE to my BD. I am using an open.file dialog but when I select an image in my field, the location of the image is not registered and I think that is the problem.
Les Agradesco.
This Data Layer:
public class Cls_D_Alumno { private static string conexion = ConfigurationManager.ConnectionStrings["CnxLogin"].ConnectionString; public static DataTable RegistrarAlumno(Cls_E_Alumno objE) { return SqlHelper.ExecuteDataTable(conexion, "Registrar_Alumno", objE.Imagen,objE.Opc); } }
This is the Entity Layer:
public class Cls_E_Alumno { private string imagen; public string imagen { get { return imagen; } set { imagen= value; } } private int opc; public int Opc { get { return opc; } set { opc = value; } } }
This is the Presentation Layer:
private void btnRegistrar_Click(object sender, EventArgs e) { try { objE.Imagen=txtImagen.Text; objE.Opc = 1; string resp = Cls_N_Alumno.RegistrarAlumno(objE).Rows[0][0].ToString(); if(resp=="1") { Limpiar(); MessageBox.Show("Registro Correctamente", "Aviso del Sistema"); } else { MessageBox.Show("Error al Registrar", "Aviso del Sistema"); } } catch(Exception ex) { } }
This is the Image of my Presentation:
In that Button of ... IT IS WHERE they are going to select the image for it I am using this method of the open File.
private void btnImagen_Click(object sender, EventArgs e) { try { this.openFileDialog1.ShowDialog(); if(this.openFileDialog1.FileName.Equals("")==false) { pictureBox1.Load(this.openFileDialog1.FileName); } } catch(Exception ex) { MessageBox.Show("No se Pudo Cargar la Imagen", "Aviso del Sistema"); } }