- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Data.OleDb;
- using System.Data.SqlClient;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- using System.IO;
- namespace WindowsFormsApplication1
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- private void button1_Click(object sender, EventArgs e)
- {
- pictureBox1.Image = ConMdb();
- }
- //读取Access数据库中的图片
- private Image ConMdb()
- {
- DataSet ds = new DataSet();
- //定义连接加密ACCESS数据库的字符串,数据库密码为xiangyu
- string strFilePath = "Provider=Microsoft.Jet.OLEDB.4.0;Data source=" + Application.StartupPath
- + "//OEMInfo.mdb;Jet OLEDB:Database Password=xiangyu";
- //定义连接数据源信息数据表为Info,其中“标识”项为Ole类型,存储的为数据。
- string sql = "select * from Info";
- OleDbConnection con = new OleDbConnection(strFilePath);
- OleDbDataAdapter da = new OleDbDataAdapter(sql, con);
- try
- {
- da.Fill(ds);
- }
- catch (Exception ex)
- {
- throw new Exception(ex.ToString());
- }
- finally
- {
- con.Close();
- con.Dispose();
- da.Dispose();
- }
- Image image = null;
- try
- {
- MemoryStream ms = new MemoryStream((byte[])ds.Tables[0].Rows[0]["标识"]);
- image = Image.FromStream(ms);
- }
- catch (Exception ex)
- {
- //image = image.Dispose();
- //throw new Exception(ex.ToString());
- }
- return image;
- }
- }
- }
利用C#从Access数据库中读取图片
最新推荐文章于 2022-04-19 11:06:17 发布