如何在asp.net c中的水晶报表中发送多个参数值

时间:2013-01-31 13:44:27

标签: c# asp.net crystal-reports

如何使用asp.net C#为水晶报表发送多个参数值但不在页面上显示记录

protected void FillOrderByDrivers(DateTime FromDate, DateTime ToDate, int ShowDriver, int SigDate)
        {
            DateTime DriverFrom = Convert.ToDateTime(txtDriverFrom.Text);
            DateTime DriverTo = Convert.ToDateTime(txtDriverTo.Text);
            int DriverSegnification = int.Parse(ddlDriverSignificantDate.SelectedValue.ToString());
            int Driver = int.Parse(ddlDrivers.SelectedValue.ToString());

            int CompanyId = int.Parse(ddlComapny.SelectedValue.ToString());

            if(reportDocument == null)
                reportDocument = new ReportDocument();

    reportDocument.Load(Server.MapPath("~/Report/OrdersByDrivers.rpt"));
            reportDocument.SetDatabaseLogon(myLogOnInfo.ConnectionInfo.UserID, myLogOnInfo.ConnectionInfo.Password, myLogOnInfo.ConnectionInfo.ServerName, myLogOnInfo.ConnectionInfo.DatabaseName);

            reportDocument.SetParameterValue("@DateFrom", DriverFrom);
            reportDocument.SetParameterValue("@DateTo", DriverTo);
            reportDocument.SetParameterValue("@CompanyID", CompanyId);
            reportDocument.SetParameterValue("@ShowDriversUsing", DriverSegnification);
            reportDocument.SetParameterValue("@SigDate", Driver);


            //reportDocument.SetDataSource(ds.Tables[0]);
            rptClients.Visible = true;
            rptClients.ReportSource = reportDocument;
            rptClients.DataBind();
            rptClients.RefreshReport();

        }

任何建议都会欢迎我错了。感谢

我已经显示了stackoverflow的link但是

1 个答案:

答案 0 :(得分:1)

希望您需要使用以下代码将值传递给存储过程,并且您的代码用于将值传递给crystal reports参数。请尝试使用以下代码。

按钮单击使用以下内容!

SqlConnection con = new SqlConnection();
SqlCommand cmd = new SqlCommand();
SqlParameter para = new SqlParameter();

ReportDocument report = new ReportDocument();
ConnectionInfo conInfo = new ConnectionInfo();

con.Open();
cmd = new SqlCommand("spGetResultdriver", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add(new SqlParameter("@DateFrom", SqlDbType.DATATYPE, LENGTH, "From"));
cmd.Parameters.Add(new SqlParameter("@DateTo", SqlDbType.DATATYPE, LENGTH, "To"));
cmd.Parameters.Add(new SqlParameter("@CompanyID", SqlDbType.DATATYPE, LENGTH, "Location"));
cmd.Parameters.Add(new SqlParameter("@ShowDriversUsing", SqlDbType.DATATYPE, LENGTH, "Location"));
cmd.Parameters.Add(new SqlParameter("@SigDate", SqlDbType.DATATYPE, LENGTH, "Location"));

cmd.Parameters[0].Value = dtpFrom.Text;
cmd.Parameters[1].Value = dtpTo.Text;
cmd.Parameters[2].Value = cbCityCode.Text;
cmd.Parameters[3].Value = dtpTo.Text;
cmd.Parameters[4].Value = cbCityCode.Text;

conInfo.DatabaseName = "db name";
conInfo.UserID = "user id";
conInfo.Password = "password";
int i = cmd.ExecuteNonQuery();
con.Close();

report.Load("report path");
SetDBLogonForReport(conInfo, report);
crvReports.ReportSource = report;
crvReports.Refresh();

使用以下代码登录信息

private void SetDBLogonForReport(ConnectionInfo conInfo, ReportDocument report)
    {
        Tables tables = report.Database.Tables;
        foreach (CrystalDecisions.CrystalReports.Engine.Table table in tables)
        {
            TableLogOnInfo tableLogonInfo = table.LogOnInfo;
            tableLogonInfo.ConnectionInfo = conInfo;
            table.ApplyLogOnInfo(tableLogonInfo);
        }
    }

试试这个!!