Click here to Skip to main content
15,896,207 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Dear All, I appreciate if someone helps me to solve my problem. I have a form like Export Form in C# windows application and there are picture box and DataGridView. I want to Send both picture box and DataGridView Rows to Crystal Report.

Actually, I can pass both but picture in one crystal report and Datagridview to another Crystal report. but when I put together in one Crystal Report it shows me the error. The error that shows in bold font.

I appreciate if someone helps me.

Here is my Code:

What I have tried:

//Picture Code
            ApplicationDataSet ApplicationInvoiceDataSet = new ApplicationDataSet();
            ExportInvoiceCrystal ExportInvoiceInfo = new ExportInvoiceCrystal();
            System.IO.MemoryStream SIMS = new System.IO.MemoryStream();

            #region Image
            ExportInvoiceImage.Image.Save(SIMS, ExportInvoiceImage.Image.RawFormat);
            byte[] ExportByte = new byte[0];
            ExportByte = SIMS.ToArray();
            ApplicationInvoiceDataSet.ImageDataTable.Rows.Add(ExportByte);       
  ExportInvoiceInfo.SetDataSource(ApplicationInvoiceDataSet.Tables["ImageDataTable"]);

// ========================================================

// DataGridView Code

            DataSet DataGridDataSet = new DataSet();
            DataTable DataGridDataTable = new DataTable();
            DataGridDataTable.Columns.Add("ItemNo", typeof(Int64));
            DataGridDataTable.Columns.Add("ItemName", typeof(string));
            DataGridDataTable.Columns.Add("ItemQuantity", typeof(Int64));
            DataGridDataTable.Columns.Add("ItemPrice", typeof(double));
            DataGridDataTable.Columns.Add("ItemTotal", typeof(double));
            foreach (DataGridViewRow DataGridRows in DataGridExportItem.Rows)
            {
                DataGridDataTable.Rows.Add(DataGridRows.Cells[0].Value, 
                DataGridRows.Cells[1].Value, DataGridRows.Cells[2].Value, 
                DataGridRows.Cells[3].Value, DataGridRows.Cells[4].Value);
            }
            DataGridDataSet.Tables.Add(DataGridDataTable);
            DataGridDataSet.WriteXmlSchema("ApplicationDataGrid.xml");
            ExportInvoiceInfo.SetDataSource(DataGridDataSet);
Posted
Updated 8-Dec-19 9:46am

You can't set multiple datatables or datasets as a source for crystal report, but... you can pass single DataSet. See:

C#
//Picture Code
//... your code here...
//Note: do not use SetDataSource yet!

//DataGridView Code
//... your code here...
//finally
//ApplicationInvoiceDataSet contains ["ImageDataTable"] already
//add DataGridView data
ApplicationInvoiceDataSet.Tables.Add(DataGridDataTable);
ExportInvoiceInfo.SetDataSource(ApplicationInvoiceDataSet);


For further details, please see: Creating Crystal Report with Multiple Tables in ASP.NET[^]
 
Share this answer
 
Thanks my dear, I solved my problem
 
Share this answer
 
Comments
Maciej Los 8-Dec-19 15:52pm    
You're very welcome.

This is not answer. Please, delete it to avoid downvoting.

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