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

本文关键字:参数 水晶 asp net 报告 | 更新日期: 2023-09-27 17:57:02

如何使用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();
        }

任何建议都会欢迎我错在哪里.谢谢

我已经显示了堆栈溢出的链接,但是

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

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

在按钮单击中使用以下!

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

试试这个 !!