我想从数据库中检索图像,但运行时发生一个错误参数无效 [英] i want to retrieve image from database but one error occurred at run time parameter is not valid

查看:68
本文介绍了我想从数据库中检索图像,但运行时发生一个错误参数无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

private void button1_Click(object sender, EventArgs e)
{
    cm = new SqlCommand("select photo from pqr where Id='abc'", cn);
    SqlDataReader rd = cm.ExecuteReader();

    if (rd.Read())
    {
        byte[] b = (Byte[])rd["photo"];
        MemoryStream ms = new MemoryStream(b);
        pictureBox1.Image = Image.FromStream(ms);//here error is occurred parameter is not Valid
    } rd.Close();
}
}







已添加标签。

[/ Edit]

推荐答案

Always Use Handler Class to Getting Image from Database. 
So i want Suggest to use this link to Solve your Problem



http://aspalliance.com/1322_Displaying_Images_in_ASPNET_Using_HttpHandlers.5 [ ^ ]


参考 - Image.FromStream :参数无效 [ ^ ]。



您可能需要转换为Bitmap然后再使用它。
Refer - Image.FromStream: Parameter not valid[^].

You might have to convert to Bitmap and then use that.


这篇关于我想从数据库中检索图像,但运行时发生一个错误参数无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆