This is a migrated thread and some comments may be shown as answers.

Passing Report Parameter

1 Answer 58 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Chris
Top achievements
Rank 1
Chris asked on 20 Nov 2014, 01:29 AM
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?

1 Answer, 1 is accepted

Sort by
0
Chris
Top achievements
Rank 1
answered on 21 Nov 2014, 08:20 PM
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.
Tags
General Discussions
Asked by
Chris
Top achievements
Rank 1
Answers by
Chris
Top achievements
Rank 1
Share this question
or