1.資料準備(準備base64的資料)
注意事項:DB裡的值,前面的desc要拿掉,只存後面就好
2.報表設計-add dataset
3.報表設計-圖片
using (MemoryStream ms = new MemoryStream())
{
gImage.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
string ss = Convert.ToBase64String(ms.ToArray());
}
add dataset & 插入圖片,設定圖片來源
// new資料表
DataTable dt = new DataTable();
dt.Columns.Add("bar", typeof(string));
//把圖轉成base64,存在datatable
using (MemoryStream ms = new MemoryStream())
{
gImage.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
string ss = Convert.ToBase64String(ms.ToArray());
dt.Rows.Add(ss);
}
// setting
reportViewer1.LocalReport.ReportPath = "rptBASE64.rdlc";
reportViewer1.LocalReport.DataSources.Clear();
reportViewer1.LocalReport.DataSources.Add(new ReportDataSource("DataSet2", dt));
reportViewer1.RefreshReport();
rdl,可藉由select來新增datatable
rdlc,雖然可以直接連DB設定,勾選table建立datatable.
但沒辦法像rdl自己寫語法,如果要建立的話,就要自己設定datatable.
rdlc
rdl