如何从访问数据库检索图像到图片框? [英] How to retrieve image from access database to picture box?

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

问题描述

while (dr.Read())
                   {
                       f_na.Text += dr[ "FirstName"].ToString();
                       L_na.Text = dr["LastName"].ToString();
                       M_na.Text = dr[ "MiddleName"].ToString();
                       PlOD.Text = dr["PlaceOfBirth"].ToString();
                       DOB.Text = dr["DOB"].ToString();
                       EM_ad.Text = dr["EmailAddress"].ToString();
                       Address.Text = dr["Address"].ToString();
                       suite.Text = dr["Suit/Unit"].ToString();
                       Post.Text = dr["PostalCode"].ToString();
                       City.Text = dr["City"].ToString();
                       provi.Text = dr["Province"].ToString();
                       Country.Text = dr["Country"].ToString();
                       gender_M.Text = dr["Gender"].ToString();
                       gender_F.Text = dr["Gender"].ToString();

**I think this code section is gives me No parameter error**
                       byte[] arr = (byte[])dr["Photo"];
   
                       if (arr.Length > 0)
                       {
                           MemoryStream mem = new MemoryStream(arr);
                           pictureBox1.Image = Image.FromStream(mem);
                       }

                   }
                   dr.Close();
                   Connection.Close();





我尝试过:



我试过了





What I have tried:

I have tried

MemoryStream mem = new MemoryStream(arr);
                           pictureBox1.Image = Image.FromStream(mem);





但我这里得到No Parameter Error就是图片示例 [ ^ ]

推荐答案

请阅读: c# - 从Access读取图像 - 参数无效 - 堆栈溢出 [ ^ ]


我使用过服务从数据集中获取图像数据,你可以从Access Query到Dataset,并按照下面的步骤进行操作



DataSet imageds = Se rviceImageClient.GetImageData(serviceimagedata);

dataGridView2.DataSource = imageds.Tables [0];



foreach(DataGridViewRow dataGridView2.Rows中的行) )

{

if(row.Cells [Image_Id]。Value!= null)

{

MemoryStream ms = new MemoryStream((byte [])row.Cells [Image]。Value);

System.Drawing.Image Image1 = System.Drawing.Image.FromStream(ms);

string sMainImagePath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)+\\ foldername;

Image1.Save(sMainImagePath +\\ + row.Cells [Image_Id]。值+。Bmp);

}

}
I have used service for getting the Image Data from Dataset, you could get it from Access Query to Dataset and follow the same procedure as did below

DataSet imageds = ServiceImageClient.GetImageData(serviceimagedata);
dataGridView2.DataSource = imageds.Tables[0];

foreach (DataGridViewRow row in dataGridView2.Rows)
{
if (row.Cells["Image_Id"].Value != null)
{
MemoryStream ms = new MemoryStream((byte[])row.Cells["Image"].Value);
System.Drawing.Image Image1 = System.Drawing.Image.FromStream(ms);
string sMainImagePath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\foldername";
Image1.Save(sMainImagePath + "\\" + row.Cells["Image_Id"].Value + ".Bmp");
}
}


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

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