报表文件保存到数据库与读取事例
sql保存字段类型image1、保存文件到数据库
FileInfo rptFile = new FileInfo("报表文件路径");
byte[] byte_pub = null;
using (FileStream Rpt2Stream = rptFile.OpenRead())
{
byte_pub = new byte;
Rpt2Stream.Read(byte_pub, 0, byte_pub.Length);
}
SqlParameter[] pars = new SqlParameter[]{
new SqlParameter("@pbstream",SqlDbType.Image)
};
pars.Value = byte_pub;
2、读取报表文件
MemoryStream ms_pub = new MemoryStream();
byte[] byte_pub = (byte[])(Jb.ds_Pub.Tables.Rows["FPbStream"]);
ms_pub.Write(Jb.byte_pub, 0, Jb.byte_pub.Length);
ms_pub.Seek(0, SeekOrigin.Begin);
using (TextReader StreamTxtRead = new StreamReader(ms_pub))
{
PageReportViewPgReport = new PageReport(StreamTxtRead);
ARptView.LoadDocument(ViewPgReport.Document);
}
给大佬点赞{:5_117:}
页:
[1]