Home > DeveloperSection > Forums > problem saving image in sql server 2014
Soleiman Ghamshadzahi
Soleiman Ghamshadzahi

Total Post:1

Posted on    December-22-2014 12:56 PM

 ASP.Net ASP.Net  SQL Server 

 0 Reply(s)
 840  View(s)
Rate this:

i have problem with saving jpeg image to sql server
below is my saving code
        string con_string = System.Configuration.ConfigurationManager.AppSettings["con_string"];
        System.Data.SqlClient.SqlConnection conobj = new System.Data.SqlClient.SqlConnection(con_string);
        string sql = "INSERT INTO Docs (nid,photo) VALUES (@nid,@photo)";
        System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand(sql, conobj);
        int length = photoupload.PostedFile.ContentLength;

        //create a byte array to store the binary image data

        byte[] imgbyte = new byte[length];

        //store the currently selected file in memeory

        HttpPostedFile img = photoupload.PostedFile;

        //set the binary data

        img.InputStream.Read(imgbyte, 0, length);

        cmd.Parameters.AddWithValue("@nid",nid_lbl .Text );
        cmd.Parameters.Add("@photo", SqlDbType.VarBinary ).Value = imgbyte;
        cmd.Connection = conobj;
and my docs table structure is like below
nid    char
photo  varbinary(max)
a new row add to docs table when i press save button but after retrieve using handler it show nothing to image control
my retrieve handler is correct problem is with save procedure
please help

Don't want to miss updates? Please click the below button!

Follow MindStick