通过C#.net和后端MSACCESS将图片保存在数据库中并在图片框中重新显示和显示 [英] Save Picture in database and Reterive and Display in Picture Box by C# .net and back end MSACCESS
本文介绍了通过C#.net和后端MSACCESS将图片保存在数据库中并在图片框中重新显示和显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要在数据库中保存图像并通过使用C#和后端MS ACCESS
解决方案
$在图片框中显示图像和显示b $ b
去抛出此链接
http://www.csharpfriends.com/Forums/ShowPost.aspx?PostID=79870 [ ^ ]
总功能由链接提供。 />
问候,
Vinay
private void btnToPB_Click(object sender,EventArgs e)
{
RefreshDBConnection();
rowNumber = 0;
pictureBox1.Image = ReadImageFromDB();
btnToPB.Text =查看第一个
私有图像ReadImageFromDB()
{
图像FetchdImg;
if( rowNumber> = 0)
{
byte [] FetchedImgBytes =(byte [] LocalDataTable.Rows [rowNumber] [Photo];
MemoryStream stream = new MemoryStream( FetchedImgBytes);
FetchedImg = Image.FromStream(stream);
返回FetchedImg;
else
{
MessageBox .Show(数据库中没有图像。请重新连接od添加一些图像);
返回null;
}
< blockquote>
string constr = Provider = Microsoft.Jet.OLEDB.4.0; Data Source = .\\PIS(ACU).mdb;;
Con = new OleDbConnection(@constr);
Con.Open();
Com = new OleDbCommand();
Com.Connection = Con;
{
Com.CommandTe xt = SELECT Picture FROM< pics> WHERE Patient_Id = + val + ,Con)
using(SqlDataReader reader = cmd。 ExecuteReader())
{
if(reader.Read())
{
byte [] picbyte = reader [ Picture ] as byte [] ??空值;
if(picbyte!= null)
{
using(MemoryStream ms = new MemoryStream(picData))
{
//加载来自的图像内存流。你是如何做到这一点取决于你是否使用Windows窗体或WPF
//。
//对于Windows窗体,您可以编写:
System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(ms);
}
}
}
}
}
I need to save image in database and reterive image and display in picture box by using C# and Back end MS ACCESS
解决方案
Hi,
Go throw this link
http://www.csharpfriends.com/Forums/ShowPost.aspx?PostID=79870[^]
Total functionality is provided by the link.
Regards,
Vinay
private void btnToPB_Click(object sender,EventArgs e) { RefreshDBConnection(); rowNumber=0; pictureBox1.Image=ReadImageFromDB(); btnToPB.Text="view 1st private Image ReadImageFromDB() { Image FetchdImg; if(rowNumber >=0) { byte[]FetchedImgBytes=(byte[]LocalDataTable.Rows[rowNumber]["Photo"]; MemoryStream stream=new MemoryStream(FetchedImgBytes); FetchedImg=Image.FromStream(stream); return FetchedImg; else { MessageBox.Show("there are no image in the database yet.please reconnect od add some Image"); return null; }
string constr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=.\\PIS(ACU).mdb;"; Con = new OleDbConnection(@constr); Con.Open(); Com = new OleDbCommand(); Com.Connection = Con; { Com.CommandText = "SELECT Picture FROM <pics> WHERE Patient_Id =" + val + ", Con) using (SqlDataReader reader = cmd.ExecuteReader()) { if (reader.Read()) { byte[] picbyte= reader["Picture"] as byte[] ?? null; if (picbyte!= null) { using (MemoryStream ms = new MemoryStream(picData)) { // Load the image from the memory stream. How you do it depends // on whether you're using Windows Forms or WPF. // For Windows Forms you could write: System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(ms); } } } } }
这篇关于通过C#.net和后端MSACCESS将图片保存在数据库中并在图片框中重新显示和显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文