Set DataTable as DataSource for Crystal Report

2019-09-16 13:26发布

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?

1条回答
Animai°情兽
2楼-- · 2019-09-16 13:56

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();
查看更多
登录 后发表回答