Dynamic columns
Hi guys,
I tried unsuccessfully the whole of last night trying to display a report through a .NET dataset. Before you say it is simple, let me explain what I am trying to do. The report basically has to be totally dynamic. I do not know the schema of the report at compile time. I generate a dynamic dataset and pass it to an empty report. However, I see no data. I thought crystal reports should be able
to infer the schema from the dataset. Right now, I am using a poor man's Datagrid to do the job. However, I will need to generate charts and graphs based on this data and crystal reports would be great
to have.
Here is some C# ASP.NET code that I tried.
-------------------------------------------------------------protected:
CrystalReportViewer CrystalReportViewer1;
// just a template for an empty report.
TestReport report = new TestReport();
String query = "Select ColumnNames from SomeTable";
SqlCommand sql= new SqlCommand(query, myConn);
DataSet testData = new DataSet("ReportSet");
DataSet tab = new DataTable("ReportSet");
SqlDataReader reader = sql.ExecuteReader();
while (reader.Read())
{
// Insert the dynamic column names
tab.Columns.Add(reader.GetString(0), typeof(System.String));
}
reader.Close();
// Some method follows for filling the dataset
// Now, basically the next 2 lines should do it.
report.SetDataSource(testData);
CrystalReportViewer1.ReportSource = report;
// However, NADA! Just an empty report :-((
I would REALLY appreciate it if someone can help me with this. Would even buy beer if they are around
Munich sometime :D
--------------------------------------------------------------------
|