Passing Report Parameter

2 posts, 0 answers
  1. Chris
    Chris avatar
    15 posts
    Member since:
    Aug 2012

    Posted 19 Nov 2014 Link to this post

    I have a form that gets  a value form the user. I call the report form (the winform with the report viewer) and pass it the value the user supplied. I thought I could pass this to the report but I can't see to figure it out.

    In the report class, I have:

               public rptTimeSheet(string sheetID)
               {
                string comStr = "SELECT * FROM vwTimeSheetReport WHERE TimeSheetID = " + sheetID;
                SqlConnection sqlConnection1 = new SqlConnection();
                SqlCommand sqlSelectCommand1 = new SqlCommand();
                SqlDataAdapter sqlDataAdapter1 = new SqlDataAdapter();
                sqlConnection1.ConnectionString = "XXXX";
                sqlSelectCommand1.CommandText = comStr;
                sqlSelectCommand1.Connection = sqlConnection1;
                sqlDataAdapter1.SelectCommand = sqlSelectCommand1;
                this.DataSource = sqlDataAdapter1;
                InitializeComponent();
            }

    Obviously, I want to pass that value to the report class, but I'm baffled as to where I should do it. I have a reportviewer in a winform and the report source is the above report class.

    How do I do this?
  2. Chris
    Chris avatar
    15 posts
    Member since:
    Aug 2012

    Posted 21 Nov 2014 in reply to Chris Link to this post

    Well, I figured it out. I moved my code to the form containing the report viewer. That way I could call it passing a parameter. I then set the report data source and it worked as expected. This would have been more obvious, but the documentation is all about filtering within the report.
Back to Top