image retrieving problem in sql server 2000
-
Following is the code , i am doing , but the error is occuring while the execution of last line. Error A generic error occurred in GDI+. Where I am doing wrong
SqlConnection con = new SqlConnection(connectionstring); con.Open(); SqlCommand cmd=new SqlCommand(); cmd.CommandText = "spSelect_a"; cmd.Connection = con; cmd.CommandType = CommandType.StoredProcedure; DataSet ds = new DataSet(); SqlDataAdapter ad = new SqlDataAdapter(cmd); ad.Fill(ds); byte[] b = (byte[])cmd.ExecuteScalar(); MemoryStream ms = new MemoryStream(); ms.Write(b, 0, b.Length); Bitmap bmp = new Bitmap(ms); **bmp.Save(Response.OutputStream,ImageFormat.Bmp);**
If you have an apple & I have an apple and we exchange our apples, then each of us will still have only one apple but if you have an idea & I have an idea and we exchange our ideas, then each of us will have two ideas!
-
Following is the code , i am doing , but the error is occuring while the execution of last line. Error A generic error occurred in GDI+. Where I am doing wrong
SqlConnection con = new SqlConnection(connectionstring); con.Open(); SqlCommand cmd=new SqlCommand(); cmd.CommandText = "spSelect_a"; cmd.Connection = con; cmd.CommandType = CommandType.StoredProcedure; DataSet ds = new DataSet(); SqlDataAdapter ad = new SqlDataAdapter(cmd); ad.Fill(ds); byte[] b = (byte[])cmd.ExecuteScalar(); MemoryStream ms = new MemoryStream(); ms.Write(b, 0, b.Length); Bitmap bmp = new Bitmap(ms); **bmp.Save(Response.OutputStream,ImageFormat.Bmp);**
If you have an apple & I have an apple and we exchange our apples, then each of us will still have only one apple but if you have an idea & I have an idea and we exchange our ideas, then each of us will have two ideas!
Pankaj Garg wrote:
A generic error occurred in GDI+.
What does the
InnerException
says ?All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia My Website | Ask smart questions
-
Pankaj Garg wrote:
A generic error occurred in GDI+.
What does the
InnerException
says ?All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia My Website | Ask smart questions
This is he only exception i am getting , the external exception was handled by the user code , was written on the Exception title.
If you have an apple & I have an apple and we exchange our apples, then each of us will still have only one apple but if you have an idea & I have an idea and we exchange our ideas, then each of us will have two ideas!
-
Following is the code , i am doing , but the error is occuring while the execution of last line. Error A generic error occurred in GDI+. Where I am doing wrong
SqlConnection con = new SqlConnection(connectionstring); con.Open(); SqlCommand cmd=new SqlCommand(); cmd.CommandText = "spSelect_a"; cmd.Connection = con; cmd.CommandType = CommandType.StoredProcedure; DataSet ds = new DataSet(); SqlDataAdapter ad = new SqlDataAdapter(cmd); ad.Fill(ds); byte[] b = (byte[])cmd.ExecuteScalar(); MemoryStream ms = new MemoryStream(); ms.Write(b, 0, b.Length); Bitmap bmp = new Bitmap(ms); **bmp.Save(Response.OutputStream,ImageFormat.Bmp);**
If you have an apple & I have an apple and we exchange our apples, then each of us will still have only one apple but if you have an idea & I have an idea and we exchange our ideas, then each of us will have two ideas!
I think this code will work just try it. And let me know it's working or not just change image format as per requirement and variable name and also that database fieldname. Response.Clear(); Response.ContentType = "image/jpeg"; System.Drawing.Image image = null; Cmd = new SqlCommand("SELECT fieldname FROM tablename where field='" + id + "'", Con); Cmd.CommandType = CommandType.Text; SqlDataReader Dr = Cmd.ExecuteReader(); if (Dr.Read()) { byte[] imageData = (byte[])Dr[0]; MemoryStream memStream = new MemoryStream(imageData); image = System.Drawing.Image.FromStream(memStream); image.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg); }