简体   繁体   English

将参数值传递给Crystal Report中使用的存储过程

[英]Passing parameter value to Stored Procedure used in Crystal Report

I am using VS 2012 with Crystal Reports. 我正在将VS 2012与Crystal Reports一起使用。 I have written a stored Procedure in MySQL with one parameter , i am using this stored procedure in my Crystal report, everything works fine but when i use export option of crystal report and i export the report to PDFs format, it contains empty report as i have set Parameter value to null in Design Time of crystal report. 我已经在MySQL中使用一个参数编写了一个存储过程,我在Crystal报表中使用了该存储过程,一切正常,但是当我使用Crystal报表的导出选项并将报表导出为PDF格式时,它包含空报表,因为在Crystal报表的“设计时间”中已将“参数值”设置为null。 My code s given below. 我的代码如下。

protected void btn_search_Click(object sender, EventArgs e)
    {

        string qry = "Call SP_GeneralReport ('" + tbx_ddoCode.Text.ToUpper() + "')";
        DataSet ds = Q.sendQueryToReport(qry);
        ReportDocument crystalReport = new ReportDocument();
        crystalReport.Load(Server.MapPath("GeneralEmpReport.rpt"));
        crystalReport.SetDatabaseLogon("root", "", "localhost", "hr");
        crystalReport.SetDataSource(ds.Tables[0]);
        CrystalReportViewer1.ReportSource = crystalReport;
    }
public DataSet sendQueryToReport(string qry)
    {
        //- if connection is closed then open the connection
        if (myConn.State == System.Data.ConnectionState.Closed)
            myConn.Open();

        //- Create command and then assign Query
        myComm = new MySqlCommand(qry, myConn);


        myAdapter = new MySqlDataAdapter(myComm);
        DataSet ds = new DataSet();
        myAdapter.Fill(ds);
        // finally close the connection
        myConn.Close();
        return ds;  
    }

In browser i pass parameter value to stored procedure using textbook, it show the accurate result in browser , but the problem comes when i export my report then it show me empty report. 在浏览器中,我使用教科书将参数值传递给存储过程,它在浏览器中显示了准确的结果,但是问题出在我导出报告然后显示为空报告时。 As to mention here in Design of Crystal report i set default value of storedprocedure to null. 就像在《水晶设计报告》中提到的那样,我将storedprocedure的默认值设置为null。

首先将CrystalReportviewer的EnableParmeterPrompt属性设置为true,然后通过Crystalreport对象将参数传递给存储过程对象,如下所示-

crystalReport.SetParameterValue(0, "parameterValue");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM