这是我的加载方法:
这里的数据源是一个存储过程,我试图从查询中获取值并将其作为参数发送到存储过程,我做错了什么?
protected void Page_Load(object sender, EventArgs e)
{
try
{
System.Data.SqlClient.SqlConnection myConnection =
new System.Data.SqlClient.SqlConnection( "user id=;" +
"password=;server=localhost;" +
"Trusted_Connection=yes;" +
"database=;" + "db;" +
"connection timeout=30");
myConnection.Open();
System.Data.SqlClient.SqlCommand myCommand_FirstName =
new System.Data.SqlClient.SqlCommand( "SELECT [Patient-ID] " +
"FROM [Patient-Info] " +
"WHERE [First Name]='" + Request.QueryString["param3"] +
"' AND [Last Name]='" + Request.QueryString["param4"] + "';"
, myConnection);
String patient_ID = "";
if (myCommand_FirstName.ExecuteScalar() != null)
{
patient_ID = myCommand_FirstName.ExecuteScalar().ToString();
}
CrystalDecisions.CrystalReports.Engine.ReportDocument reportDocument = new CrystalDecisions.CrystalReports.Engine.ReportDocument();
CrystalReportViewer1.RefreshReport();
ParameterField paramField = new ParameterField();
ParameterFields paramFields = new ParameterFields();
paramField.Name = "@ID";
ParameterDiscreteValue paramDiscreteValue = new ParameterDiscreteValue();
paramDiscreteValue.Value = patient_ID;
paramField.CurrentValues.Add(paramDiscreteValue);
paramFields.Add(paramField);
paramField = new ParameterField();
paramField.Name = "@Med";
paramDiscreteValue = new ParameterDiscreteValue();
paramDiscreteValue.Value = Request.QueryString["param1"];
paramField.CurrentValues.Add(paramDiscreteValue);
paramFields.Add(paramField);
paramField = new ParameterField();
paramField.Name = "@Year";
paramDiscreteValue = new ParameterDiscreteValue();
paramDiscreteValue.Value = Request.QueryString["param2"];
paramField.CurrentValues.Add(paramDiscreteValue);
paramFields.Add(paramField);
reportDocument.Load(Server.MapPath("CrystalReport1.rpt"));
CrystalReportViewer1.ParameterFieldInfo = paramFields;
CrystalReportViewer1.ReportSource = reportDocument;
myConnection.Close();
}
}
这就是我定义CrystalReportViewer的地方:
<form id="form1" runat="server">
<div>
<CR:CrystalReportViewer ID="CrystalReportViewer1" width="903px" height="1170px" runat="server" AutoDataBind="True" ToolPanelView="None" OnInit="CrystalReportViewer1_Init" DisplayToolbar="False" EnableDatabaseLogonPrompt="False" GroupTreeImagesFolderUrl="" ReportSourceID="CrystalReportSource1" ToolbarImagesFolderUrl="" ToolPanelWidth="200px" EnableParameterPrompt="False" />
<CR:CrystalReportSource ID="CrystalReportSource1" runat="server">
<Report FileName="CrystalReport1.rpt">
</Report>
</CR:CrystalReportSource>
</div>
</form>
答案 0 :(得分:0)
请设置如下参数:
reportDocument.SetParameterValue("@ID", patient_ID);
reportDocument.SetParameterValue("@Med", Request.QueryString["param1"]);
reportDocument.SetParameterValue("@Year", Request.QueryString["param2"]);