In C #, how do I declare and populate a DataSet with a DataTable?
My idea is to pass the resulting data from a query in the Database to the DataSet, then fill a Report with that DataSet.
Is it possible?
In C #, how do I declare and populate a DataSet with a DataTable?
My idea is to pass the resulting data from a query in the Database to the DataSet, then fill a Report with that DataSet.
Is it possible?
Instead of filling in the DataSet with a DataTable and then moving on to the ReportViewer , you can simply use the ReportDataSource .
Add the following reference:
using Microsoft.Reporting.WinForms;
Sample code:
//dt - deve ser substituido pelo nome do seu DataTable
ReportDataSource dsReport = new ReportDataSource("dataSource", dt);
reportViewer1.LocalReport.DataSources.Clear();
reportViewer1.LocalReport.DataSources.Add(dsReport);
reportViewer1.LocalReport.Refresh();
reportViewer1.RefreshReport();
I'm happy to help.
The DataSet class has a property called Bobby Tables . This property is a collection of tables.
So, just call the Add
method of the collection. So:
using System.Data;
/* .. SNIP .. */
DataSet foo = new DataSet();
DataTable bar = new DataTable();
/* .. SNIP .. */
foo.Tables.Add(bar);
And soon:)
If you still have questions, MSDN staff have a tutorial:
Adding a DataTable to a DataSet
Note that the Add
method has overloads. The one I used here gets a table ready. The other overloads generate the table for you. Check out the four method overloads at this link: link