从数据库中检索图像并显示在图片框中 [英] Retrieve image from Database and display in picturebox

查看:143
本文介绍了从数据库中检索图像并显示在图片框中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用



 qry =   
qry = SELECT TOP 1 Image FROM T_ImageStore
cmd =新的OleDbCommand(qry,conn)
Dim img As Byte()= DirectCast(cmd.ExecuteScalar(),Byte ())
Dim ms As MemoryStream = New MemoryStream(img)
PictureBox1。 Image = 图片 .FromStream(ms)





要检索此代码来自数据库的图像和图片框中的显示。



当PictureBox1.Image = Image.FromStream(ms)行装入时出现错误



bug是



System.Drawing.dll中发生了'System.ArgumentException'类型的未处理异常



附加信息:参数无效。



我找不到错误是什么,可以任意1帮助,



谢谢

解决方案

 void DispalyImage()
{

SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds,Images);
int count = ds.Tables [Images]。Rows.Count;

if(ds.Tables.Count> 0&& ds.Tables [0] .Rows.Count> 0)
{
var data =(Byte [])(ds.Tables [Images]。行[count - 1] [Image]);
MemoryStream stream = new MemoryStream(data);
pictureBox1.Image = Image.FromStream(stream);
}

}


 Dim myMS As New IO.MemoryStream 

PictureBox1.Image = System.Drawing.Image.FromStream(myMS)





我希望,它会对你有所帮助.. ......


I use

qry = ""
qry = "SELECT TOP 1 Image FROM T_ImageStore"
cmd = New OleDbCommand(qry, conn)
Dim img As Byte() = DirectCast(cmd.ExecuteScalar(), Byte())
Dim ms As MemoryStream = New MemoryStream(img)
PictureBox1.Image = Image.FromStream(ms)



this code to retrieve image from database and display in picture Box.

I get an error when PictureBox1.Image = Image.FromStream(ms) line encounted

The bug is

An unhandled exception of type 'System.ArgumentException' occurred in System.Drawing.dll

Additional information: Parameter is not valid.

I couldn't find what the error is, Can any 1 help in this pls,

Thanks

解决方案

void DispalyImage()
    {

        SqlDataAdapter da = new SqlDataAdapter(cmd);
        DataSet ds = new DataSet();
        da.Fill(ds, "Images");
        int count = ds.Tables["Images"].Rows.Count;

        if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
        {
            var data = (Byte[])(ds.Tables["Images"].Rows[count - 1]["Image"]);
            MemoryStream stream = new MemoryStream(data);
            pictureBox1.Image = Image.FromStream(stream);
        } 

    }


Dim myMS As New IO.MemoryStream

PictureBox1.Image = System.Drawing.Image.FromStream(myMS)



I hope, It will help for you........


这篇关于从数据库中检索图像并显示在图片框中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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