如何从访问数据库检索图像到图片框?
问题描述:
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");
}
}