Link to home
Start Free TrialLog in
Avatar of melli111
melli111Flag for United States of America

asked on

Visual Studio Reporting do report based off of set of values

Right now, I have a working report that passes parameters to an SQL query that fills a dataset, and displays the data using the DataSet.  What I would like to be able to do is change the code so that I can fill the dataset based off a SET of values for one particular field.  The code that I have now works great, I just neeed to know how to change it so that I can send a SET of values as a parameter.  Here is the code I have now


        EstimatingReportViewer.Reset();
        EstimatingReportViewer.ProcessingMode = ProcessingMode.Local;
            string conString = "Data Source=server;Initial Catalog=table;Persist Security Info=True;User ID=userid;Password=password";
            SqlConnection conReport = new SqlConnection(conString);
            SqlCommand cmdReport = new SqlCommand();
            SqlDataReader drReport;
            DataSet DataSetReporting = new dsReporting();
           conReport.Open();
           cmdReport.CommandType = CommandType.Text;
           cmdReport.Connection = conReport;
           cmdReport.CommandText = "SELECT * FROM dbo.table1 WHERE Period >= @StartingDate and Period <= @EndingDate AND column1 = @Project AND column2 = @Version ORDER BY Period,column2";
cmdReport.Parameters.Add(new SqlParameter("@StartingDate", SqlDbType.Int));
                cmdReport.Parameters.Add(new SqlParameter("@EndingDate", SqlDbType.Int));
                cmdReport.Parameters.Add(new SqlParameter("@Project", SqlDbType.NVarChar, 50));
                cmdReport.Parameters.Add(new SqlParameter("@Version", SqlDbType.NVarChar, 50));
                cmdReport.Parameters["@StartingDate"].Value = begindate;
                cmdReport.Parameters["@EndingDate"].Value = endingdate;
                cmdReport.Parameters["@Project"].Value = projectname;
                cmdReport.Parameters["@Version"].Value = versionname;
                drReport = cmdReport.ExecuteReader();
                DataSetReporting.Tables[0].Load(drReport);
                DataTable table = DataSetReporting.Tables[0];
                drReport.Close();
                conReport.Close();
                EstimatingReportViewer.LocalReport.ReportPath = Server.MapPath("Report1.rdlc");
                EstimatingReportViewer.LocalReport.DataSources.Add(new ReportDataSource(EstimatingReportViewer.LocalReport.GetDataSourceNames()[0], table));
                EstimatingReportViewer.Visible = true;
ASKER CERTIFIED SOLUTION
Avatar of Mike McCracken
Mike McCracken

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial