Click here to Skip to main content
15,888,816 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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:
C#
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

1 solution

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[^]
 
Share this answer
 
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 )
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

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