private void Form1_Load(object sender, EventArgs e) { this.Text = DisplayHeaderText; SqlConnection cn = new SqlConnection("Data Source=" + RptServer + ";Initial Catalog=" + RptDatabase + ";user=" + RptUser + ";Password=" + RptPassword); SqlCommand Cmd = new SqlCommand(); SqlDataAdapter myAdapter = new SqlDataAdapter(); Cmd.CommandText = " Select * From vw_SalesWithImage"; Cmd.Connection = cn; myAdapter.SelectCommand = Cmd; cn.Open(); DataSet ds = new DataSet(); myAdapter.Fill(ds); cn.Close(); DataTable dttmp = ds.Tables[0]; dttmp.Columns.Add("IsImage", System.Type.GetType("System.Byte[]")); for (int index = 0; index < ds.Tables[0].Rows.Count; index++) { if (dttmp.Rows[index]["ImgFile"].ToString() != "") { string s = dttmp.Rows[index]["ImgFile"].ToString(); LoadImage(dttmp.Rows[index], s); } else { LoadImage(dttmp.Rows[index], ""); } } // Finally display report in crystal report viewer ReportDocument crDoc = new CrystalDecisions.CrystalReports.Engine.ReportDocument(); string rptPath = Application.StartupPath; crDoc.Load(rptPath + "\\SalesWithImage.rpt"); crDoc.SetDataSource(dttmp); crptViewer.ReportSource = crDoc; crDoc.DataDefinition.FormulaFields[0].Text = "'" + FltrHeaderText + "'"; } private void LoadImage(DataRow objDataRow, string FilePath) { if (FilePath == "") { return; } if (File.Exists( FilePath)) { FileStream fs = new FileStream(FilePath, System.IO.FileMode.Open, System.IO.FileAccess.Read); //byte[] Image = new byte[fs.Length]; //fs.Read(Image, 0, Convert.ToInt32(fs.Length)); BinaryReader br = new BinaryReader(fs); byte[] imgbyte = new byte[fs.Length + 1]; imgbyte = br.ReadBytes(Convert.ToInt32((fs.Length))); fs.Close(); objDataRow["IsImage"] = imgbyte; } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)