Link to home
Start Free TrialLog in
Avatar of Codingitup
Codingitup

asked on

How to retieve image from sql server asp.net c#

Hi All,

I've got a sql table called ImageTest that has a column called ImageData. I use the following stored procedure to return this data as follows: -

                        SqlCommand cmd2 = new SqlCommand("web.Get_Image", myConn);
                        SqlDataReader dr2 = null;
                        cmd2.CommandType = CommandType.StoredProcedure;
                        cmd2.Parameters.Add(new SqlParameter("@ImgID", cmbLoggedPartno.Text));

                        SqlParameter parm = new SqlParameter("@Image", SqlDbType.Image);
                        parm.Direction = ParameterDirection.Output; // This is important! 
                        cmd2.Parameters.Add(parm);

                        dr2 = cmd2.ExecuteReader();

Open in new window


How do I set my imagebox imgPreview1 to display this image returned from the sql procedure please?

Many Thanks
Lee
ASKER CERTIFIED SOLUTION
Avatar of Rajar Ahmed
Rajar Ahmed
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Codingitup
Codingitup

ASKER

Hi,

Sorry I'm new to this coding. I've tried part of the example as: -

                        SqlCommand cmd2 = new SqlCommand("web.Get_Image", myConn);
                        cmd2.CommandType = CommandType.StoredProcedure;
                        SqlDataAdapter sda = new SqlDataAdapter();
                        DataTable dt = new DataTable();

                        myConn.Open();
                        sda.SelectCommand = cmd2;
                        sda.Fill(dt);
                        myConn.Close();
                        sda.Dispose();

                        Byte[] bytes = (Byte[])dt.Rows[0]["Image_File"];

Open in new window


But can't understand how to set the imagebox to display it.

Many Thanks
Lee