使用C#在crisytal报告中显示图像 [英] showing image in crisytal report using c#
本文介绍了使用C#在crisytal报告中显示图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
updated , but now showing image
regards
I am using studio 2008 i am trying to display image in Cristal report
string query = "select * from gateentry2 where passno='" + strpassno_imgname + "'";
objclsvrb.objSqladp = new SqlDataAdapter(query,objclsvrb.constring);
DataSet1 ds1 = new DataSet1();
objclsvrb.objSqladp.Fill(ds1, "gateentry2");
DataTable dt = new DataTable();
DataRow drow = null;
//dt.Columns.Add("Image", System.Type.GetType("System.Byte[]"));
dt.Columns.Add("Image", typeof(byte[]));
drow = dt.NewRow();
FileStream fs = default(FileStream);
BinaryReader br = default(BinaryReader);
if (File.Exists(Application.StartupPath + "\\Images\\" + strpassno_imgname + ".Jpg"))
{
fs = new FileStream(Application.StartupPath + "\\Images\\" + strpassno_imgname + ".Jpg", FileMode.Open);
}
else
{
fs = new FileStream(AppDomain.CurrentDomain.BaseDirectory + "NoPhoto.jpg", FileMode.Open);
}
br = new BinaryReader(fs);
byte[] imgbyte = new byte[fs.Length + 1];
imgbyte = br.ReadBytes(Convert.ToInt32((fs.Length)));
drow[0] = imgbyte;
dt.Rows.Add(drow);
br.Close();
fs.Close();
CrystalReport1 rptobj = new CrystalReport1();
//dt = ds1.Tables[0];
rptobj.SetDataSource(dt);
crystalReportViewer1.ReportSource = rptobj;
推荐答案
试试看:
DataRow卓尔;
Hi, Try this:
DataRow drow;
dt.Columns.Add("Image", typeof(byte[]));
drow = dt.NewRow();
////您缺少大括号
然后使用方括号代替
// you were missing the braces
and then, use square braces instead
drow[0] = imgbyte;
如您所见,它非常简单.
As you can see, its pretty simple.
这篇关于使用C#在crisytal报告中显示图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文