Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Visual Studio Reporting do report based off of set of values

Posted on 2011-02-18
1
Medium Priority
?
270 Views
Last Modified: 2012-05-11
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;
0
Comment
Question by:melli111
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 101

Accepted Solution

by:
mlmcc earned 2000 total points
ID: 34931451
You have to change this line.

cmdReport.CommandText = "SELECT * FROM dbo.table1 WHERE Period >= @StartingDate and Period <= @EndingDate AND column1 = @Project AND column2 = @Version ORDER BY Period,column2";


However, most SQLs do not accept sets of values as a parameter.

Which field are you filtering on and what are the Values?

mlmcc
0

Featured Post

Enroll in October's Free Course of the Month

Do you work with and analyze data? Enroll in October's Course of the Month for 7+ hours of SQL training, allowing you to quickly and efficiently store or retrieve data. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…

609 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question