如何使用asp.net c#从数据库中检索图像# [英] how to retrive image form the database using asp.net c #

查看:56
本文介绍了如何使用asp.net c#从数据库中检索图像#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的

我想从sql数据库中检索图像,在sql数据库中,图像数据类型是图像,我想在图像控件中检索。 plz帮我解决

dear
I want to retrieve a image form the sql data base and in the sql database the image data type is image and i want to retrieve in the image control. plz help me out

推荐答案

try
{
    SqlCommand cmdSelect=new SqlCommand("select Picture" +
          " from tblImgData where ID=@ID",this.sqlConnection1);
    cmdSelect.Parameters.Add("@ID",SqlDbType.Int,4);
    cmdSelect.Parameters["@ID"].Value=this.editID.Text;

    this.sqlConnection1.Open();
    byte[] barrImg=(byte[])cmdSelect.ExecuteScalar();
    string strfn=Convert.ToString(DateTime.Now.ToFileTime());
    FileStream fs=new FileStream(strfn,
                      FileMode.CreateNew, FileAccess.Write);
    fs.Write(barrImg,0,barrImg.Length);
    fs.Flush();
    fs.Close();
    pictureBox1.Image=Image.FromFile(strfn);
}
catch(Exception ex)
{
    MessageBox.Show(ex.Message);
}
finally
{
    this.sqlConnection1.Close();
}





几个链接:

使用Microsoft .NET从SQL Server中检索和检索图像 [ ^ ] br />
使用ASP.NET中的数据库中的GridViewImages C# [ ^ ]



few links:
Storing and Retrieving Images from SQL Server using Microsoft .NET[^]
GridViewImages from DB in ASP.NET using C#[^]


这些链接可以帮助您

http://www.dotnetcurry.com/ShowArticle.aspx?ID=129 [ ^ ]

http://www.roseindia.net/answers/viewqa/Java-Beginners/21658-How-to- retrieve-image-from-database.html [ ^ ]

www.redmondpie.com/inserting-in-and-retrieving-image-from-sql-server-database-using-c/ [ ^ ]
May these links help you
http://www.dotnetcurry.com/ShowArticle.aspx?ID=129[^]
http://www.roseindia.net/answers/viewqa/Java-Beginners/21658-How-to-retrieve-image-from-database.html[^]
www.redmondpie.com/inserting-in-and-retrieving-image-from-sql-server-database-using-c/[^]


在这个例子中,我从数据库中提取了二进制代码。





SqlCommand命令=新的SqlCommand(从表中选择图像,连接);



byte [] objByte =((byte [])命令。 ExecuteScalar());



Syst em.IO.MemoryStream objStream = new System.IO.MemoryStream(objByte);



Picture.Image = Image.FromFile(objStream);
In this example i have fetched the binary code from the database.


SqlCommand command = new SqlCommand("Select Image From Table",Connection);

byte[] objByte = ((byte[])command.ExecuteScalar());

System.IO.MemoryStream objStream =new System.IO.MemoryStream(objByte);

Picture.Image=Image.FromFile(objStream);


这篇关于如何使用asp.net c#从数据库中检索图像#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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