Ankush

Ankush

  • NA
  • 267
  • 63.6k

Retrieve image of greater than 1mb from sql server using c#

Feb 24 2016 12:27 AM
I want to retrieve images of greater than 1 mb in size from sql server in windpws application using c#.
When I try to insert the image of greater than 1 mb in size, it is inserted, but when I try to retrieve the image the runtime error is occurring i.e. "Parameter is not valid".
The code I tried to retrieve the image is :-
  1. name = cbCust_Name.SelectedValue.ToString();  
  2. //btnDisplay_Click(sender, e);  
  3. SqlConnection cnn = new SqlConnection(conString);  
  4. MemoryStream stream = new MemoryStream();  
  5. cnn.Open();  
  6. SqlCommand command = new SqlCommand("Select Cust_Image from Photo where Cust_Name= '" + name + "'", cnn);  
  7. byte[] image = (byte[])command.ExecuteScalar();  
  8. stream.Write(image, 0, image.Length);  
  9. //cnn.Close();  
  10. Bitmap bitmap = new Bitmap(stream);  
  11. pictureBox1.Image = bitmap;  
How can I retrieve the image of bigger size i.e. greater than 1 mb in size.
 
Thanks in Advance ...!!!
 

Answers (1)