检索图像到图片框时,为什么我的错误参数无效? [英] Why I got error parameter is not valid while retrieving image to picture box?
本文介绍了检索图像到图片框时,为什么我的错误参数无效?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试从数据库检索图像到图片框,我收到错误消息:缓冲区不能为空。参数名称:缓冲区和参数无效。有人可以帮我弄清楚如何避免这种异常或如何解决问题?这是我的代码:
I am trying to retrieve an image from database to a picturebox and I am getting the error message: "Buffer cannot be null. Parameter name: Buffer" and "Parameter is invalid". Can someone help me to figure out how to avoid this exception or how to fix the issue? Here is my Code:
public void loadimage()
{
ConnectionStringSettings conSetting = ConfigurationManager.ConnectionStrings["MyDBConnectionString"];
string connectionString = conSetting.ConnectionString;
conn = new SqlConnection(connectionString);
conn.Open();
try
{
if (conn.State == System.Data.ConnectionState.Open)
{
string sss = "SELECT ProductImage from ProductServices where ProductCode=@productCode";
SqlCommand cmd = new SqlCommand(sss, conn);
cmd.Parameters.AddWithValue("@productCode", txtCode.Text);
Byte[] getImg = (Byte[])cmd.ExecuteScalar();
MemoryStream stream = new MemoryStream(getImg);
Image img = Image.FromStream(stream);
pictureBoxProduct.Image = img;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally {
conn.Close();
}
}
我尝试过:
我试过改变查询和peremeter但仍然是同样的问题。
What I have tried:
I have tried changing query and peremeter but still same problem.
推荐答案
看看这里:< a href =https://www.codeproject.com/Tips/465950/Why-do-I-get-a-Parameter-is-not-valid-exception-wh>为什么我得到参数不是有效。我从数据库中读取图像时出现异常? [ ^ ]
这篇关于检索图像到图片框时,为什么我的错误参数无效?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文