首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何从access数据库中检索照片

如何从access数据库中检索照片
EN

Stack Overflow用户
提问于 2013-05-20 17:42:51
回答 1查看 2K关注 0票数 0
代码语言:javascript
运行
复制
private void Profile_Load(object sender, EventArgs e)
{
    OleDbConnection con = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=  C:\Users\jay.desai\Documents\Visual Studio 2008\Projects\Employee Profile\Employee.mdb");
    OleDbCommand cmd = new OleDbCommand("select * from Profile where Emp_No=" + txtEmployeeNo.Text + "", con);
    cmd.CommandType = CommandType.Text;
    OleDbDataAdapter da = new OleDbDataAdapter(cmd);
    DataSet ds = new DataSet();
    da.Fill(ds, "Profile");
    txtEmployeeNo.Text = ds.Tables[0].Rows[0][0].ToString();
    txtName.Text = ds.Tables[0].Rows[0][1].ToString();
    txtAddress.Text = ds.Tables[0].Rows[0][2].ToString();
    txtSex.Text = ds.Tables[0].Rows[0][3].ToString();
    txtMobNo.Text = ds.Tables[0].Rows[0][4].ToString();
    dtp.Text = ds.Tables[0].Rows[0][5].ToString();
    textBox1.Text = ds.Tables[0].Rows[0][6].ToString();
    pictureBox1.Image = ds.Tables[0].Rows[0][7];
}

我已经在ms access中创建了一个数据库,其中有一个名为Profile的表,其中包含一个字段照片具有OLE对象数据类型我手动在字段中插入了一个.bmp图像现在我想在picturebox中检索该图像,但在运行时我收到了这样的错误:“无法隐式地将类型‘对象’转换为'System.Drawing.Image‘。存在显式转换(您缺少强制转换吗?)”

EN

回答 1

Stack Overflow用户

发布于 2013-05-20 17:46:47

需要有Image类型的对象来设置Picture Box Image,所以可以使用内存流和Image.FromStream方法来获取图像

代码语言:javascript
运行
复制
byte[] bimg= (byte[])ds.Tables[0].Rows[0][7];
MemoryStream mstream = new MemoryStream(bimg);
pictureBox1.Image = Image.FromStream(mstream);
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16646677

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档