problem saving image in sql server 2014

Total Post:1

Points:7
 1303  View(s)
Ratings:
Rate this:

hi
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;
        conobj.Open();
        cmd.ExecuteNonQuery();
        conobj.Close();
***************
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
thanks

Answer