0

如何使用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的链接,但是

4

1 回答 1

1

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

在按钮单击中使用以下!

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

试试这个 !!

于 2013-02-01T06:06:46.857 回答