c# winform读取access数据库中的二进制图片

c# winform读取access数据库中的二进制图片

private void ReadImage()
        {
            System.Data.OleDb.OleDbConnection dbConnection = new System.Data.OleDb.OleDbConnection();
            dbConnection.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Application.StartupPath + "\\DB.mdb;Persist Security Info=True";
            dbConnection.Open();
            System.Data.OleDb.OleDbCommand cmd = new System.Data.OleDb.OleDbCommand("select * from tb_images",dbConnection);
            System.Data.OleDb.OleDbDataReader reader = cmd.ExecuteReader(CommandBehavior.CloseConnection);
            if (reader.Read())
            {
                System.IO.MemoryStream ms = new System.IO.MemoryStream((byte[])reader[1]);
                this.BackgroundImage = Image.FromStream(ms);
            }
            reader.Close();
            dbConnection.Close();
        }

nathanma

leave a comment

Create Account



Log In Your Account