I am working Windows form Application in c#.I like to create crystal report from datagridview values instead of using database values. How can i do this,Is it possible to do this.how can add the values in crystal report dynamically
views:
51answers:
1
+1
A:
You could create a DataSet and populate it with the values from the DataGridView. You can then bind the Crystal Report to the DataSet.
Something along the lines of:
DataSet ds = new DataSet();
ds = FetchDataFromGrid();
CrystalReport myReport = new CrystalReport()
myReport.SetDataSource(ds);
crystalReportViewer1.ReportSource = myReport
To retrieve the rows from a DataGridView you will need something like this:
DataSet ds = new DataSet();
DataTable dt = new DataTable();
foreach (DataGridViewRow item in this.dataGridView1.Rows)
{
DataRow dr = dt.NewRow();
if (item.DataBoundItem != null)
{
dr = (DataRow)((DataRowView)item.DataBoundItem).Row;
dt.ImportRow(dr);
}
}
ds.Tables.Add(dt);
Barry
2010-07-29 07:41:06
I can i fetch the data from grid
ratty
2010-07-29 09:11:49
@barry Thanks you very much for your answer
ratty
2010-07-29 10:29:11
@ratty - no problem
Barry
2010-07-29 10:34:38
barry i got some error in that one column not allowed null exception
ratty
2010-07-29 12:44:09
my first gird view column is null how can omit that column
ratty
2010-07-29 12:45:41
@barry did u get correct answer for ur coding
ratty
2010-07-29 13:03:26
@ratty - You could either set `EnforceConstraints` to false on the DataSet or replace the Null values with a valid value. Maybe you could either post some more details or ask a new question?
Barry
2010-07-29 13:10:25
Why mark this as unanswered? I answered your question, and added more than you initially asked for.
Barry
2010-07-29 16:02:23