Search code examples
c#asp.netcrystal-reports

Set DataTable as DataSource for Crystal Report


I am creating a report in Visual Studio 2008. My crystal report is created using TTX or Data Definition File and I am passing a DataTable as its data source. I have already checked my TTX and DataTable columns if they are the same.

Here is the code:

string strReportFilePath = ConfigurationManager.AppSettings["ReportsPath"] + "MyReport.rpt";
rpt.Load(strReportFilePath);
DataTable dt = GetDataTableFromOracle("select item_no, descr from items");
crvReportViewer.ReportSource = rpt;
crvReportViewer.DataBind();

The result is no data on crystal report. Am I missing something? What's wrong with my code?


Solution

  • Adding TableName will solve this problem.

    string strReportFilePath = ConfigurationManager.AppSettings["ReportsPath"] + "MyReport.rpt";
    rpt.Load(strReportFilePath);
    DataTable dt = GetDataTableFromOracle("select item_no, descr from items");
    dt.TableName = "FileNameOfTheTTX";
    crvReportViewer.ReportSource = rpt;
    crvReportViewer.DataBind();