Quantcast
Channel: CSharp Forum Latest Questions
Viewing all articles
Browse latest Browse all 32065

crystal report with runtime dataset

$
0
0
i want to show data in crystal report. that data comes through dataset which is created at RUNTIME. the datatable has two field one contains image and other name of image. i want to display all the image and name below image. i am new to crystal report so dont know what all setting i have to do. i am pasting my code below. let me know what setting is needed in crystal view side and any changes if required in my code. i have not done anything in crystal report




code
 DataTable table = new DataTable("ImageTable");
                    DataColumn column = new DataColumn("MyImage");
                    column.DataType = System.Type.GetType("System.Byte[]");
                    column.AllowDBNull = true;
                    column.Caption = "My Image";
                    DataColumn column1 = new DataColumn("imgName");
                    table.Columns.Add(column);
                    table.Columns.Add(column1);
                    foreach (FileInfo fi in target.GetFiles())
                    {
                        FileStream fs = new FileStream(Path.Combine(this.imgFolder.SelectedPath.ToString(), fi.Name), FileMode.Open);
                        BinaryReader br = new BinaryReader(fs);
                        DataRow row = table.NewRow();
                        row["MyImage"] = (object)(br.ReadBytes((int)br.BaseStream.Length));
                        string[] filename = fi.Name.Split('.');
                        row["imgName"] = filename[0];
                        table.Rows.Add(row);

                    }
                    string ImagePath = (System.Environment.CurrentDirectory);
                    ImagePath = ImagePath.Replace("bin\\Debug", "CrystalReport1.rpt");
                    ReportDocument rptDoc = new ReportDocument();
                    rptDoc.Load(ImagePath);                  
                    DataSet ds = new DataSet();
                    ds.Tables.Add(table);
                   rptDoc.SetDataSource(ds.Tables["ImageTable"]);                  
                    crystalReportViewer1.ReportSource = rptDoc;

Viewing all articles
Browse latest Browse all 32065

Trending Articles