我正在使用VS 2012和Crystal Reports。我用MySQL写了一个带有一个参数的存储过程,我在我的水晶报表中使用这个存储过程,一切正常,但是当我使用水晶报表的导出选项并将报表导出为PDF格式时,它包含空报表,因为我在水晶报表的设计时将参数值设置为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;
}在浏览器中,我使用教科书将参数值传递给存储过程,它在浏览器中显示了准确的结果,但是当我导出我的报告时,问题出现了,它显示为空报告。在这里提到,在水晶报表的设计中,我将storedprocedure的默认值设置为null。
发布于 2014-10-25 16:17:23
首先将CrystalReportviewer的EnableParmeterPrompt属性设置为true,然后通过Crystalreport对象将参数传递给存储过程对象,如下所示-
crystalReport.SetParameterValue(0, "parameterValue");
https://stackoverflow.com/questions/26544307
复制相似问题