如何在crystal report和where条件中动态添加查询

时间:2014-02-14 10:08:16

标签: asp.net crystal-reports-2008

如何在水晶报表中动态添加查询以及从多个表中选择记录或列的条件以及如何在水晶报表中添加字段

protected void Button1_Click(object sender, EventArgs e)
{
    string sql = "select * from tblStudentFees";
    ds = cc.ExecuteDataset(sql);

    ReportDocument doc = new ReportDocument();
    doc.Load(Server.MapPath("~/Andorid_Class_App/ReportFees.rpt"));

    doc.SetDataSource(ds);
    CrystalReportViewer1.ReportSource = doc;
}

1 个答案:

答案 0 :(得分:0)

您可以在使用任何查询结果集时将DataSet传递给水晶报表,因此以您的示例为例,您只需根据您的要求更改查询:

protected void Button1_Click(object sender, EventArgs e)
{
    string sql = "select * from tblStudentFees
                  join sometable on tblStudents.sometable_id = sometable.id
                  where sometable.value = somecriteria";
    DataSet ds = new DataSet();
    ds = cc.ExecuteDataset(sql);

    ReportDocument doc = new ReportDocument();
    doc.Load(Server.MapPath("~/Andorid_Class_App/ReportFees.rpt"));

    CrystalReportViewer1.ReportSource = doc;
    CrystalReportViewer1.LocalReport.DataSources.Clear();
    CrystalReportViewer1.DataSources.Add(
    new Microsoft.Reporting.WebForms.ReportDataSource("DataSetIdentifier", ds)
    );
}