将参数值传递给Crystal Report中使用的存储过程
本文关键字:存储过程 Report Crystal 参数 值传 | 更新日期: 2023-09-27 18:27:37
我使用的是带有Crystal Reports的VS 2012。我在MySQL中用一个参数写了一个存储过程,我在我的Crystal报告中使用这个存储过程,一切都很好,但当我使用Crystal报告的导出选项并将报告导出为PDF格式时,它包含空报告,因为我在Crystal报告设计时将parameter值设置为null。我的代码如下。
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;
}
在浏览器中,我使用教科书将参数值传递给存储过程,它在浏览器中显示准确的结果,但当我导出报告时,问题出现了,然后它显示空报告。正如在水晶设计报告中提到的,我将存储过程的默认值设置为null。
首先将CrystalReportviewer的EnableParmeterPrompt属性设置为true,然后通过Crystalreport对象将参数传递给存储过程对象,如下所示-
crystalReport.SetParameterValue(0, "parameterValue");