Using untyped datasets in Crystal Reports

I am creating a runtime dataset on page load. In this dataset, I add columns like this:

CrystalDecisions.CrystalReports.Engine.ReportDocument orpt = 
   new CrystalDecisions.CrystalReports.Engine.ReportDocument();

DataTable table = new DataTable("DataSet1");

table.Columns.Add("Fname", typeof(System.String));
table.Columns.Add("Lname", typeof(System.String));
table.Columns.Add("Salary", typeof(System.String));
DataRow row = table.NewRow();
row["Fname"] = "Mathew";
row["Lname"] = "Hayden";
row["Salary"] = "5000$";

table.Rows.Add(row);
ds.Tables.Add(table);

orpt.Load(MapPath("CrystalReport3.rpt"));
orpt.SetDataSource(ds.Tables[0]);
CrystalReportViewer1.ReportSource = orpt;

      

Entries are not displayed in CrystalReport3.rpt when I go to run the program. Tell me how to set these columns in Crystal Reports 3!

+1


source to share


2 answers


What happens if you move your code from Page_Load to the Page_Init event handler of an ASP.NET page?

Try setting the AutoDataBind property to "true":



Gets or sets whether automatic data is used to bind to the report source. If the value is set to True, the DataBind () method is called after OnInit () or Page_Init ().

Another tip: have you tried calling the RefreshReport () (or Refresh () in older versions) method of the CrystalReportViewer1 object?

+1


source


Instead

orpt.SetDataSource(ds.Tables[0]);

      

Do



orpt.SetDataSource(ds.Tables["table_name"]);

      

table_name is the table name that you specified for the table

+1


source







All Articles