水晶报表 (悬赏100)
我现在想用水晶报表打印数据库中的内容,文字可以打印出来但图片不行,我数据库中存的是图片的路径,现在请高人帮忙解决,如何在水晶报表中显示图片,这是现在使用的代码:(我用的数据库是access),我要具体的做法谢谢。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Data.SqlClient;
using CrystalDecisions.CrystalReports.Engine;
using System.Web.Caching;
namespace chc
{
public partial class PrintForm : Form
{
public PrintForm()
{
//InitializeComponent();
}
private void PrintForm_Load(object sender, EventArgs e)
{
DataSet ds = new DataSet();
SqlConnection cn = new SqlConnection();
SqlDataAdapter da = new SqlDataAdapter("select * from FirstTable", cn);
SqlCommandBuilder bd = new SqlCommandBuilder(da);
da.Fill(ds);
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
DataSet ds1 = new DataSet();
if (ds.Tables[0].Rows[@"图片"] != null)
{
string path = Microsoft.SqlServer.Server.MapPath(ds.Tables[0].Rows["图片"].ToString());
if (File.Exists(path))
{
ds1.Tables.Add("student");
FileStream fs = new FileStream(path, FileMode.Open);
BinaryReader br = new BinaryReader(fs);
addrow(ds, ds1, i, br);
fillimg(ds1);
}
}
}
}
/// <summary>
/// 把文件找到读成二进制,然后调用addrow方法
/// </summary>
/// <param name="dssafe"></param>
/// <param name="ds"></param>
/// <param name="i"></param>
/// <param name="br"></param>
public void addrow(DataSet dssafe, DataSet ds, int i,BinaryReader br)
{
ds.Tables[0].Columns.Add("编号", typeof(System.String ));
ds.Tables[0].Columns.Add("品名", typeof(System.String));
ds.Tables[0].Columns.Add("图片", typeof(System.Byte[]));
ds.Tables[0].Columns.Add("长", typeof(System.Int32));
ds.Tables[0].Columns.Add("宽", typeof(System.Int32));
ds.Tables[0].Columns.Add("高", typeof(System.Int32));
ds.Tables[0].Columns.Add("数量", typeof(System.Int32));
ds.Tables[0].Columns.Add("单位", typeof(System.String));
ds.Tables[0].Columns.Add("设备相关性能及参数", typeof(System.String));
ds.Tables[0].Columns.Add("单价", typeof(System.Int32));
ds.Tables[0].Columns.Add("金额", typeof(System.Int32));
DataRow row = ds.Tables[0].NewRow();
row["编号"] = dssafe.Tables[0].Rows["编号"].ToString();
row["品名"] = dssafe.Tables[0].Rows["品名"].ToString();
row["图片"] = dssafe.Tables[0].Rows["图片"].ToString();
row["长"] = dssafe.Tables[0].Rows["长"].Int32();
row["宽"] = dssafe.Tables[0].Rows["宽"].Int32();
row["高"] = dssafe.Tables[0].Rows["高"].Int32();
row["数量"] = dssafe.Tables[0].Rows["数量"].Int32();
row["单位"] = dssafe.Tables[0].Rows["单位"].ToString();
row["设备相关性能及参数"] = dssafe.Tables[0].Rows["设备相关性能及参数"].ToString();
row["单价"] = dssafe.Tables[0].Rows["单价"].Int32();
row["金额"] = dssafe.Tables[0].Rows["金额"].Int32();
ds.Tables[0].Rows.Add(row);
}
/// <summary>
/// 把数据填充到新的DATASET里,即ds,然后把ds设置为报表的数据源
/// </summary>
/// <param name="ds"></param>
public void fillimg(DataSet ds)
{
if (Cache["dataset"] == null)
{
ds.ReadXmlSchema(Microsoft.SqlServer.Server.MapPath("dataTable.xsd"));
Cache["dataset"] = ds;
ReportDocument rp = new ReportDocument();
rp.Load(Microsoft.SqlServer.Server.MapPath("CrystalReport1.rpt"));
rp.SetDataSource(ds.Tables[0]);
CrystalReportViewer1.ReportSource = rp;
}
else
{
ds = (DataSet)Cache["dataset"];
ReportDocument rp = new ReportDocument();
rp.Load(Microsoft.SqlServer.Server.MapPath("CrystalReport1.rpt"));
rp.SetDataSource(ds.Tables[0]);
CrystalReportViewer1.ReportSource = rp;
}
}
}
}