如何从asp.net中的ms访问数据库中检索图像? [英] how to retrieve image from ms access database in asp.net?
问题描述
您好,我已经在ms访问数据库中保存了一些图像,我想在前端的Image字段中检索这些图像。我以OLE对象格式保存图像。每当我试图检索那些图像时,它都会给我一个错误文件'C:\Program Files \Common Files \ microsoftoft Shared\DevServer\10.0\130064593738380337'已经存在。。请解决我的问题问题。谢谢....
<前lang =c#> 受保护 void DropDownList1_SelectedIndexChanged( object sender,EventArgs e)
{
cn.Open();
OleDbCommand cm = new OleDbCommand( select * from ImageCollection其中img_id =' + DropDownList1.SelectedItem.ToString()+ ' ,cn);
OleDbDataAdapter da = new OleDbDataAdapter(cm);
OleDbDataReader dr = cm.ExecuteReader();
尝试
{
if (dr.Read())
{
string image1 = Convert.ToString(DateTime.Now.ToFileTime());
string image2 = Convert.ToString(DateTime.Now.ToFileTime());
FileStream fs1 = new FileStream(image1,FileMode.CreateNew,FileAccess.Write);
FileStream fs2 = new FileStream(image2,FileMode.CreateNew,FileAccess.Write);
byte [] bimage1 =( byte [])dr [ passport_photo];
byte [] bimage2 =( byte [])dr [ sign_photo];
fs1.Write(bimage1, 0 ,bimage1.Length - 1 );
fs2.Write(bimage2, 0 ,bimage2.Length - 1 );
fs1.Flush();
fs2.Flush();
Image1.ImageUrl = Convert.ToString(fs1);
Image2.ImageUrl = Convert.ToString(fs2);
}
dr.Close();
cn.Close();
}
catch (例外情况)
{
throw ex;
}
借助恢复访问下载来检索ms访问数据
发布[已删除垃圾邮件链接]包含许多用于恢复ms访问数据库的有用解决方案
Hello, I have saved some images in ms access database and i want to retrieve those images in Image field in front end. I have saved images in "OLE Object" format. Whenever i"m trying to retrieve those images it gives me an error "The file 'C:\Program Files\Common Files\Microsoft Shared\DevServer\10.0\130064593738380337' already exists.". Please solve my problem. Thanks....
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
cn.Open();
OleDbCommand cm = new OleDbCommand("select * from ImageCollection where img_id='"+DropDownList1.SelectedItem.ToString()+"'",cn);
OleDbDataAdapter da = new OleDbDataAdapter(cm);
OleDbDataReader dr = cm.ExecuteReader();
try
{
if (dr.Read())
{
string image1 = Convert.ToString(DateTime.Now.ToFileTime());
string image2 = Convert.ToString(DateTime.Now.ToFileTime());
FileStream fs1 = new FileStream(image1, FileMode.CreateNew, FileAccess.Write);
FileStream fs2 = new FileStream(image2, FileMode.CreateNew, FileAccess.Write);
byte[] bimage1 = (byte[])dr["passport_photo"];
byte[] bimage2 = (byte[])dr["sign_photo"];
fs1.Write(bimage1, 0, bimage1.Length - 1);
fs2.Write(bimage2, 0, bimage2.Length - 1);
fs1.Flush();
fs2.Flush();
Image1.ImageUrl = Convert.ToString(fs1);
Image2.ImageUrl = Convert.ToString(fs2);
}
dr.Close();
cn.Close();
}
catch (Exception ex)
{
throw ex;
}
Retrieve ms access data with the aid of recovery for access download
Post [spam link removed] contains of many helpful solutions for restoring ms access databases
这篇关于如何从asp.net中的ms访问数据库中检索图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!