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.
He开发者_Go百科re 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?
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();
精彩评论