1个回答
展开全部
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.OleDb;
using System.IO;
using System.Data;
namespace SavePdfToAcess
{
class Program
{
static void Main(string[] args)
{
using (OleDbConnection con = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=test.mdb"))
{
con.Open();
//写入PDF
string query = "insert into TestTable(PDF) values (@pdf)";
using (OleDbCommand cmd = new OleDbCommand(query, con))
{
DirectoryInfo dir = new DirectoryInfo("input_PDF");
foreach (var item in dir.GetFiles("*.pdf"))
{
byte[] buff = File.ReadAllBytes(item.FullName);
OleDbParameter p = new OleDbParameter("@pdf", OleDbType.Binary);
p.Value = buff;
cmd.Parameters.Add(p);
cmd.ExecuteNonQuery();
}
}
//读出PDF
using (OleDbCommand cmd = new OleDbCommand("select * from TestTable", con))
{
DataTable dt = new DataTable();
dt.Load(cmd.ExecuteReader());
foreach (DataRow item in dt.Rows)
{
string id = item[0].ToString();
byte[] pdfData = (byte[])item[1];
File.WriteAllBytes("output_PDF\\" + id + ".pdf", pdfData);
}
}
}
}
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |