簡體   English   中英

如何在ASP.NET C#中的Crystal Report中發送多個參數值

[英]How to send multiple parameter value in crystal report in asp.net c#

我如何使用asp.net C#發送Crystal Report的多個參數值,但不顯示頁面上的記錄

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的鏈接 ,但是

希望您需要使用以下代碼將值傳遞給存儲過程,並且您的代碼用於將值傳遞給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);
        }
    }

嘗試這個 !!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM