为什么crystal report在Asp.net web应用程序中不显示任何内容?

为什么crystal report在Asp.net web应用程序中不显示任何内容?,asp.net,Asp.net,我首先创建了数据集,然后创建了crystal report。我已将该crystal report附加到web表单,但在运行该web表单后,crystal report没有显示任何输出。请帮助我获取输出。 我正在使用visual studio 2013 protected void Page_Load(object sender, EventArgs e) { ReportDocument crystalReport = new ReportDocument();

我首先创建了数据集,然后创建了crystal report。我已将该crystal report附加到web表单,但在运行该web表单后,crystal report没有显示任何输出。请帮助我获取输出。 我正在使用visual studio 2013

 protected void Page_Load(object sender, EventArgs e)
    {
        ReportDocument crystalReport = new ReportDocument();
        crystalReport.Load(Server.MapPath("~/CrystalReport.rpt"));
        DataSet dsCustomers = GetData("select * from customers");
        crystalReport.SetDataSource(dsCustomers);
        CrystalReportViewer1.ReportSource = crystalReport;
    }

    private DataSet GetData(string query)
    {
        string conString = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
        SqlCommand cmd = new SqlCommand(query);
        using (SqlConnection con = new SqlConnection(conString))
        {
            using (SqlDataAdapter sda = new SqlDataAdapter())
            {
                cmd.Connection = con;

                sda.SelectCommand = cmd;
                using (DataSet dsCustomers = new DataSet())
                {
                    sda.Fill(dsCustomers, "DataTable1");
                    return dsCustomers;
                }
            }
        }
    }
ASPX:


看起来您缺少数据绑定

protected void Page_Load(object sender, EventArgs e)
{
    ReportDocument crystalReport = new ReportDocument();
    crystalReport.Load(Server.MapPath("~/CrystalReport.rpt"));
    DataSet dsCustomers = GetData("select * from customers");
    crystalReport.SetDataSource(dsCustomers);
    CrystalReportViewer1.ReportSource = crystalReport;
    CrystalReportViewer1.DataBind();
}

尝试在页面加载中调用数据绑定以查看自动绑定是否未按您的预期工作?来自@Nikki9696的一条评论说了同样的话,但在您这样做之前一个小时,因此您的帖子不应被视为已接受的答案。仍然没有得到输出请确保您的数据集dsCustomers有行
protected void Page_Load(object sender, EventArgs e)
{
    ReportDocument crystalReport = new ReportDocument();
    crystalReport.Load(Server.MapPath("~/CrystalReport.rpt"));
    DataSet dsCustomers = GetData("select * from customers");
    crystalReport.SetDataSource(dsCustomers);
    CrystalReportViewer1.ReportSource = crystalReport;
    CrystalReportViewer1.DataBind();
}