首页 文章

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

提问于
浏览
0

我正在使用VS 2012和Crystal Reports . 我在MySQL中用一个参数编写了一个存储过程,我在我的Crystal报表中使用这个存储过程,一切正常但是当我使用水晶报表的导出选项并将报表导出为PDF格式时,它包含空报表为i在水晶报告的设计时间中将参数值设置为空 . 我的代码如下 .

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;  
    }

在浏览器中我使用教科书将参数值传递给存储过程,它在浏览器中显示准确的结果,但问题出现在我导出我的报告然后它显示空报告 . 如此处在Crystal of Crystal报告中提到的,我将storedprocedure的默认值设置为null .

1 回答

  • 0

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

    crystalReport.SetParameterValue(0, "parameterValue");

相关问题