Click here to Skip to main content
13,355,275 members (52,994 online)
Rate this:
 
Please Sign up or sign in to vote.
I use DataGridView for the user to type the inputs, than i add the data from the DGV to datatable , than i bind this datatable to DataSet, than in the rdlc when i select this DataSet and DataTable it shows me Just the Header of the Table and nothing more.

p.s I crated a DataTable in the DataSet manually with the columns so i can refer to that table cuz otherwise i couldnt select it in the rdlc report

here is the code im using:
DataSet2 ds = new DataSet2();
            DataTable dt=ds.Table2;

            DataRow dr = null;
            for (int i = 0; i < dataGridView1.Rows.Count-1; i++)
            {
                dr = dt.NewRow();
                dr["id"] = dataGridView1.Rows[i].Cells[0].Value;
                dr["name"] = dataGridView1.Rows[i].Cells[1].Value;
                dr["car"] = dataGridView1.Rows[i].Cells[2].Value;
                dr["amount"] = dataGridView1.Rows[i].Cells[3].Value;
                dr["price"] = dataGridView1.Rows[i].Cells[4].Value;
                dr["totalprice"] = dataGridView1.Rows[i].Cells[5].Value;
               // MessageBox.Show(dr["Vetura"].ToString());
                dt.Rows.Add(dr);
            }

            foreach (DataTable table in ds.Tables)
            {
                foreach (DataRow row in table.Rows)
                {
                    foreach (DataColumn column in table.Columns)
                    {
                        object item = row[column];
                        // read column and item
                        MessageBox.Show(item.ToString());
                    }
                }
            }


            Raport ra = new Raport();
            ra.ShowDialog();
Posted 12-Jul-15 7:48am

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

In your code, you don't actually assign the data table as a data source anywhere. Also you don't call the AcceptChanges[^] method for the data table so the changes may not be visible to the report.

Have a look at for example this article which nicely explains how to use a data table as a source for the data for a report: Dynamic Binding Of RDLC To ReportViewer[^]
  Permalink  
Comments
Member 10425037 12-Jul-15 13:10pm
   
I dont assign the data table , because , i created the DataTable in the DataSet manually
(Righclick in dataset ADD -> DataTable and created the fields that i need, because otherwise i cant selct the fields in the RDLC report )
Mika Wendelius 12-Jul-15 13:13pm
   
Ok, so it's a typed dataset. Have you tried adding the AcceptChanges and going through the article I posted?
Member 10425037 12-Jul-15 13:25pm
   
I will try accept Changes, now and will tell you the response
Member 10425037 12-Jul-15 13:27pm
   
Btw. i tryed this code to ensure myself that data inside datatable is stored and ti works,

foreach (DataTable table in ds.Tables)
{
MessageBox.Show(table.ToString());
foreach (DataRow row in table.Rows)
{
MessageBox.Show(row.ToString());
foreach (DataColumn column in table.Columns)
{
object item = row[column];
// read column and item
MessageBox.Show(item.ToString());
}
}
}
Member 10425037 12-Jul-15 13:39pm
   
Still not working , it doesnt show me anything , just the header of the table with the columns , and nothing more below the header is blank
Mika Wendelius 12-Jul-15 14:05pm
   
I believe there are few options:
- the report is binded to a different datatable or dataset that you're filling => try setting the datasource in code
- the report layout isn't designed to show detail rows => check the layout

I still believe that the first one is the likeliest, that you use a different dataset than what is binded to the report. Check that you don't create a new instance of the typed dataset anywhere.
Member 10425037 13-Jul-15 19:09pm
   
It seems that you are right , when i try to run the foreach loop that i wrote up, to check if ther is data there are no Data in the DataSet.
I think the issue is that i fill the dataset in form1 , than when i call it in the form2 it deletes all the data stored in the dataset.
How can achieve this ... :(
Mika Wendelius 14-Jul-15 0:50am
   
Try commenting out the dataset creation:
//DataSet2 ds = new DataSet2();

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy |
Web03 | 2.8.180111.1 | Last Updated 12 Jul 2015
Copyright © CodeProject, 1999-2018
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100