获取参数无效异常(复杂) [英] getting parameter is not valid exception(Complicated)
本文介绍了获取参数无效异常(复杂)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我花了2个月的时间尝试将图像插入数据库并再次检索!,我已成功将图像插入数据库,但是当我尝试将其检索到图片框时出现此异常
顺便说一句,我正在使用扫描仪,所以我只需要浏览一个文件,我只想将其从Picturebox插入数据库,然后再次将其检索到Picturebox
插入步骤
i have spent 2 months trying to insert an image into database and retrieve it again!,i have succeeded to insert the image into database ,but when i try to retrieve it into picturebox i get this exception
btw i''m using scanner so i dun need to browse a file i just want to insert it from picturebox into database and retrieve it again into picturebox
Insert Step
//---------------
MemoryStream ms = new MemoryStream();
PBoxGuestImage.Image.Save(ms, ImageFormat.Jpeg);
Byte[] PicArray = new Byte[ms.Length];
ms.Position = 0;
ms.Read(PicArray, 0, PicArray.Length);
CMD.CommandText = "Insert Into TestTable(TestImage) Values (@ParTestImage)"
CMD.Parameters.AddWithValue("@ParTestImage", PicArray);
//---------------
这很好用
检索步骤
this works great
Retrieve Step
Image NewImage;
byte[] content = (byte[])TestReader["TestImage"];
TestPictureBox.Image = null;
using (MemoryStream stream = new MemoryStream(content, 0, content.Length))
{
stream.Write(content, 0, content.Length);
NewImage = Image.FromStream(stream, true); //at this line i get the exception
}
TestPictureBox.Image = NewImage;
反正有解决这个问题的方法吗?
is there anyway to solve this issue ?
Thanks.
推荐答案
根据 Image.FromStream [^ ]该异常,因为流不是有效的图像格式.
尝试打开FileStream到图像,然后使用Image.FromStream
查看它是否正常工作,如果可以,则您从TestReader["TestImage"]
According to Image.FromStream[^] you get that exception because the stream is not a valid image format.
Try to open a FileStream to an image and useImage.FromStream
to see if it works, if it does then there is something wrong with the data you get fromTestReader["TestImage"]
这篇关于获取参数无效异常(复杂)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文