从数据库中检索图像到图片框时获取错误“参数无效” [英] Getting error 'Parameter is not valid' while retrieving the image into picture box from database
本文介绍了从数据库中检索图像到图片框时获取错误“参数无效”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已编写此代码用于从数据库检索图像到图片框。我在这一行得到了这些错误'参数无效''pictureBox1.Image = Image.FromStream(stm);
I have written this code for retrieving image from database to picturebox. I got these error 'Parameter is not valid' at this line 'pictureBox1.Image = Image.FromStream(stm);
Byte[] imagebyte = new Byte[0];
imagebyte = (Byte[])(dr[Pic_Image]);
MemoryStream stm = new MemoryStream(imagebyte);
pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
pictureBox1.Image = Image.FromStream(stm);
它将该图像存储为数据库中的0x53797374656D2E44726177696E672E4269746D6170,是吗?请解决此错误。
It is storing that image as 0x53797374656D2E44726177696E672E4269746D6170 in database, would u pls solve this error.
推荐答案
本地文件夹中存储的图像名称(图像)和存储的图像数据库中的名称
imgPic.src = string.Concat(Images /,Convert.ToString(objRow [ImagesName]));
Stored Images in Local Folder Name (Images) and Stored Images Name in Database
imgPic.src = string.Concat("Images/", Convert.ToString(objRow["ImagesName"]));
Hi Tarun,
你是否正确地从数据库中获取数据。
我认为你已经以错误的格式保存了图像plz尝试下面的代码
将图像写入字节数组
Hi Tarun,
U r fetching data from database correctly.
I think u have saved image in wrong format plz try below code
write image to byte array
FileStream fs = new FileStream(@"C:\Users\ku102\Pictures\bitmap\usertile36.bmp", FileMode.Open, FileAccess.Read);
byte[] imgbnry = new byte[fs.Length];
fs.Read(imgbnry, 0, imgbnry.Length);
fs.Close();
将字节数组传递给后端以保存
pass byte array to backend for saving
cmd.Parameters.Add("@img", System.Data.SqlDbType.Image);
cmd.Parameters["@img"].Value= imgbnry;
cmd.ExecuteNonQuery();
祝你好运; - )
good luck ;-)
这篇关于从数据库中检索图像到图片框时获取错误“参数无效”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文