Crystal报表查看器给出错误:“提供的参数无效。无法打开行集。”

时间:2013-05-18 04:57:47

标签: c# asp.net crystal-reports

我有一个水晶报告,即要用存储过程填充,但是当我在.rpt文件中放入任何参数的程序时,它会给我一个错误,如

  

“提供的参数无效。无法打开行集。”

我的代码如下:

public void GroupwiseRegistrationReport()
{
    SqlConnection connection;
    DataSet ds = new DataSet();
    DataTable dt = new DataTable();
    connection = gen.con;
    string SP = "";
    SqlCommand command = connection.CreateCommand();
    SqlTransaction transaction = null;

    try
    {
        connection.Open();
        transaction = connection.BeginTransaction();
        if (rblReportFrom.SelectedValue == "0")
        {
            SP = "SPGroupwiseIndustriesEM1Report";
        }
        else
        {
            SP = "SPGroupwiseIndustriesEM2Report";
        }

        ValueData = new ArrayList();

        ParameterData[0] = "@fromdate";
        ValueData.Add(txtTotalBetweenFrom.Text.ToString().Trim());

        ParameterData[1] = "@todate";
        ValueData.Add(txtTotalBetweenTo.Text.ToString().Trim());

        ds = gen.FunSearch_Trans(ParameterData, ValueData, SP, transaction, command);
        dt = ds.Tables[0];
        if (ds.Tables[0].Rows.Count > 0)
        {
            if (rblReportFrom.SelectedValue == "0")
            {
                repdoc.Load(Server.MapPath("~\\admin\\Reports\\Groupwise-EM-I-Registration-Report.rpt"));
            }
            else
            {
                repdoc.Load(Server.MapPath("~\\admin\\Reports\\Groupwise-EM-II-Registration-Report.rpt"));
            }
            repdoc.SetDataSource(ds.Tables[0]);

            configureCrystalReports();
            crvMSMEReportViewer.ReportSource = repdoc;
            //Response.Buffer = true;
            //Response.ClearContent();
            //Response.ClearHeaders();

            //repdoc.ExportToHttpResponse(ExportFormatType.PortableDocFormat, Response, true, "Exported Report");

            tablereportviewer.Visible = true;
        }
        else
        {
            tablereportviewer.Visible = false;
            message("No Records Found.");
        }
        transaction.Commit();
    }
    catch (Exception ex)
    {
        tablereportviewer.Visible = false;
        error.LogError(ex);
        transaction.Rollback();
    }
    finally
    {
        connection.Close();
    }
}

我错过了什么或者我无法解决的问题请帮助我..

处理水晶报告的最佳方法是使用数据集还是直接存储过程?

更新

我改变了我的代码如下,但现在给我的消息如:“缺少参数值。  “。但是我只有两个参数可以通过”@fromdate“和”@todate“

这是一段代码:

  doc = new ReportDocument();
        doc.Load(Server.MapPath("~\\admin\\Reports\\Groupwise-EM-II-Registration-Report.rpt"));
        doc.SetDatabaseLogon(ConfigurationManager.AppSettings["userName"], ConfigurationManager.AppSettings["pwd"], ConfigurationManager.AppSettings["serverName"], "databaseName", false);
        doc.SetParameterValue("@fromdate", txtTotalBetweenFrom.Text.ToString());
        doc.SetParameterValue("@todate", txtTotalBetweenTo.Text.ToString());
        crvMSMEReportViewer.ReportSource = doc;
        crvMSMEReportViewer.RefreshReport();

1 个答案:

答案 0 :(得分:0)

protected void Page_Load(object sender, EventArgs e)
    {    
      if (Session["ReportDataSet"] != null)
         {
           crvAccountReportParameter.ReportSource = (ReportDocument)Session["ReportDataSet"];
         }
    }
private void LoadReport()
{
    doc = new ReportDocument();
    DataSet dsData = null;
    dsData = objAccountReportBAL.getAccountRegister(txtTotalBetweenFrom.Text.ToString(), txtTotalBetweenTo.Text.ToString());            
    doc.Load(Server.MapPath("CrSalesReport.rpt"));      
    doc.SetDataSource(dsData.Tables[0]); 
    Session["ReportDataSet"] = rptDoc;
    crvAccountReportParameter.ReportSource = rptDoc;
    crvAccountReportParameter.DataBind();
}