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‘。存在显式转换(您缺少强制转换吗?)”
发布于 2013-05-20 17:46:47
需要有Image
类型的对象来设置Picture Box Image,所以可以使用内存流和Image.FromStream
方法来获取图像
byte[] bimg= (byte[])ds.Tables[0].Rows[0][7];
MemoryStream mstream = new MemoryStream(bimg);
pictureBox1.Image = Image.FromStream(mstream);
https://stackoverflow.com/questions/16646677
复制相似问题