Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have the following code:

protected void ddlCompanyList_SelectedIndexChanged(object sender, EventArgs e)
{

    string strConnectionString = ConfigurationManager.ConnectionStrings[Constants.ConnectionStringName].ConnectionString;
    string strCustomerID = CommonCode.GetCurrentCustomerID();
    string strUserID = CommonCode.GetCurrentUserID().ToString();
    DropDownList ddl = sender as DropDownList;
    string strRSReportLinkID = ddl.SelectedValue;
    using (SqlConnection connection = new SqlConnection(strConnectionString))

    {
        connection.Open();
        SqlCommand command = new SqlCommand("Test_GetReportSettingsForReport", connection);
        command.CommandType = CommandType.StoredProcedure;
        command.Parameters.AddWithValue("@CustomerID", strCustomerID);
        command.Parameters.AddWithValue("@UserId", strUserID);
        command.Parameters.AddWithValue("@RSReportLinkID", strRSReportLinkID);

        SqlDataReader reader = command.ExecuteReader();

        if (reader.HasRows)
        {
            while (reader.Read())
            {
                string strURL = reader.GetValue(3).ToString();
                GetReportPath(strURL);

            }
        }

        else
        {
           /* Console.WriteLine("No rows found.");*/
        }

        reader.Close();
        connection.Close();
    }

}

protected void GetReportPath(string strURL)
{
    this.ReportViewer1.ServerReport.ReportPath = "/" + strURL;
}

Quite simply, every time a report is selected from my dropdown list ddlCompanyList_SelectedIndexChanged will run which just uses a stored procedure to find the URL of the report selected from the drop down. This will then be passed onto GetReportPath which will pass the reports URL into the ReportView.

Everything works fine so far, however I have decided to add CustomerID as a parameter in my report on SSRS. Passing parameters into a stored procedure was easy, however I'm a bit lost when it comes to passing a parameter (CustomerID) into the report itself. Since strCustomerID is automatically populated with the customer's ID thanks to a code I wrote, it would be great if I could just pass strCustomerID as the parameter for my report, so that users don't have to manually enter their own ID.

enter image description here

Anyone have any suggestions? Thanks for the help.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
187 views
Welcome To Ask or Share your Answers For Others

1 Answer

You can use ServerReport.SetParameters:

ReportParameter p = new ReportParameter("CustomerID", strCustomerID);

this.reportViewer1.ServerReport.SetParameters(new ReportParameter[] { p });

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...