sql保存字段类型image
1、保存文件到数据库
FileInfo rptFile = new FileInfo("报表文件路径");
byte[] byte_pub = null;
using (FileStream Rpt2Stream = rptFile.OpenRead())
{
byte_pub = new byte[Rpt2Stream.Length];
Rpt2Stream.Read(byte_pub, 0, byte_pub.Length);
}
SqlParameter[] pars = new SqlParameter[]{
new SqlParameter("@pbstream",SqlDbType.Image)
};
pars[0].Value = byte_pub;
2、读取报表文件
MemoryStream ms_pub = new MemoryStream();
byte[] byte_pub = (byte[])(Jb.ds_Pub.Tables[0].Rows[0]["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))
{
PageReport ViewPgReport = new PageReport(StreamTxtRead);
ARptView.LoadDocument(ViewPgReport.Document);
}
|