Error: Parameter is not valid.
At line no 9 : of this below code
con.Open();
SqlCommand command1 = new SqlCommand("select imgfile from myimages where imgname=@param", con);
SqlParameter myparam = command1.Parameters.Add("@param", SqlDbType.NVarChar, 30);
myparam.Value = txtimgname.Text;
byte[] img = (byte[])command1.ExecuteScalar();
MemoryStream str = new MemoryStream();
string s1=str.Write(img, 0, img.Length);
Bitmap bit = new Bitmap(s1);
Response.ContentType = "image/jpeg";//or you can select your imagetype from database or directly write it here
bit.Save(Response.OutputStream, ImageFormat.Jpeg);
con.Close();
Loading
AlanPosted Aug 6, 2008, 4:50 PM
When you pass a string to the Bitmap constructor it has to be a filename.
So, I'd try instead:
MemoryStream str = new MemoryStream();
str.Write(img, 0, img.Length);
Bitmap bit = new Bitmap(str);