问题
I am using Crystal Report with VS 10,
I have added DataSet.
Now if There's only One Table in DataSet then data is being displayed, while if i add Two Tables with Link, then Data is not being display.
And i am taking fields from this table of DataSet(XSD).
How to overcome this problem.
Thanks In Advance. Khilen
回答1:
You need to bind the DataTable(s) that you intend to use instead of binding the entire DataSet. This SO answer shows a very good example: https://stackoverflow.com/a/8341474/283895
(Code copied from that article)
ReportDocument rpt = new ReportDocument();
rpt.load();
rpt.Database.Tables[0].SetDataSource(ds.Tables[0]);
this.crystalReportViewer1.ReportSource = rpt;
回答2:
What I'm used to do is ;
- add 2 dataset to crstal report.
- Below code for blinding 2 dataset into same report.
C#
public partial class Default2 : System.Web.UI.Page
{
SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["MyCtr1"].ConnectionString);
SqlConnection cn1 = new SqlConnection(ConfigurationManager.ConnectionStrings["MyCtr2"].ConnectionString);
ReportDocument rdoc = new ReportDocument();
DataTable ds = new DataTable();
DataTable ds1 = new DataTable();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
loadreport();
}
private void loadreport()
{
{
cn.Open();
SqlDataAdapter da = new SqlDataAdapter("select * from [MyTable1] where (Number LIKE '" + DropDownList1.Text + "') ", cn);
da.Fill(ds);
cn.Close();
{
{
cn1.Open();
SqlDataAdapter da1 = new SqlDataAdapter("select * from [MyTable2] where (No LIKE '" + DropDownList1.Text + "') ", cn1);
//DataTable ds1 = new DataTable();
da1.Fill(ds1);
cn1.Close();
}
rdoc.Database.Tables[0].SetDataSource(ds);
rdoc.Database.Tables[1].SetDataSource(ds1);
InvoiceReport.ReportSource = rdoc;
InvoiceReport.DataBind();
}
来源:https://stackoverflow.com/questions/18443141/display-data-in-crystal-report-when-more-than-one-table-in-dataset