Click here to Skip to main content
15,893,564 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
XML
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;
Posted
Updated 7-Nov-12 20:54pm
v3

1 solution

Hi, Try this:

DataRow drow;

C#
dt.Columns.Add("Image", typeof(byte[]));

C#
drow = dt.NewRow();
// you were missing the braces

and then, use square braces instead

C#
drow[0] = imgbyte;


As you can see, its pretty simple.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900