developer.com
Search EarthWeb
CodeGuru | Gamelan | Jars | Wireless | Discussions
Navigate developer.com
Architecture & Design  
Database  
Java
Languages & Tools
Microsoft & .NET
Open Source  
Project Management  
Security  
Techniques  
Voice  
Web Services  
Wireless/Mobile
XML  
Technology Jobs  

   Developer.com Webcasts:
  The Impact of Coding Standards and Code Reviews

  Project Management for the Developer

  Defining Your Own Software Development Methodology

  more Webcasts...




See the Winners!


Developer Jobs

Be a Commerce Partner
Computer Hardware
Compare Prices
Phone Cards
Baby Photo Contest
Disney World Tickets
Memory
KVM over IP
Online Universities
Condos For Sale
Desktop Computers
Boat Donations
Corporate Awards
KVM Switches
Career Education

 

Click Here
Web Devs:
Moonlight as a Game Developer and Win Cool Prizes by Accepting the RIA Run Challenge

Now, your mission--should you choose to accept: Take your shot at gaming stardom if you think you might have what it takes to build a cool RIA game and you could win an Xbox 360 or other fabulous prizes. Hurry! You only have until May 15, 2008 to enter. »

 
Article:
Leveraging Your Flash Development with Silverlight

You're not giving up Flash any time soon (and we don't blame you.) But if you could get your Flash application working in Silverlight, why wouldn't you? We show you the tools and techniques required to have your rockin' Flash application rolled for Silverlight. Learn more here. »

 
Article:
What Does it Take to Build the Best RIA?

With the proliferation of Rich Interactive Application (RIA) platform choices out there, you no longer have to take a one-size-fits-all approach to developing your next RIA application. Knowing the strengths (and weaknesses) of each platform can help you to decide the best RIA for your next application. »

 
Developer News -
SaaS Tool Offers Custom Database Development    May 9, 2008
Microsoft’s Automated Agent: Can We Talk?    May 7, 2008
Borland Finally Sells CodeGear    May 7, 2008
Red Hat Heads For The JON 2.0    May 7, 2008
Free Tech Newsletter -

Project Management Guide: Developing a Web Site. Best Practices, Tips and Strategies. Download Exclusive eBook Now.

Adding RDL-Resident Code to Reporting Services Reports
By William R. Vaughn

Go to page: 1  2  3  Next  

When using the ReportViewer control in Visual Studio (2005 or 2008), you have ample opportunities to craft logic-driven SQL to build the rowset passed to the report or even munge the data values returned. Often, all you need to do is generate a string that's based on input parameters and pass these into a Report Definition Language (RDL) property. For example, in the following subroutine (see Listing 1), I generate an SQL string that can be passed to the CommandText based on a couple of input parameters. Ah, no. This code does not in of itself protect against SQL injection, but if you make sure the user does not provide the parameter values directly, your report will be safe to deploy.

Shared Function GetCustomerSQL(ByVal strInParm As String, _
   ByVal strDebug As String, intMaxRows as Integer) As String
      Dim strSELECTView As String    ' Set to production report
      If strDebug = "" Then
         strSELECTView = "SELECT TOP " & CStr(intMaxRows) & _
         "  * FROM AddressesByLocation "
      Else    ' Production
         strSELECTView = "SELECT * FROM AddressesByLocation "
      End If
      Dim strWHERE As String = "WHERE (CountryRegionCode = '" _
         & strInParm & "') "
      Dim strORDERBY As String = " ORDER BY CountryRegionCode," _
         & " City, PostalCode"
      If UCase(strInParm) = "ALL" Then
         ' Use View without WHERE clause
         Return strSELECTView & strORDERBY
      Else
         ' Use View with WHERE clause
         Return strSELECTView & strWHERE & strORDERBY
      End If
End Function

Listing 1: Generate an SQL string based on input parameters

This code can be used in lieu of a dataset reference in the RDL report definition by invoking it using the RDL Code= operator. That's what I'm going to discuss in this article—the mechanics of setting up the report and how to imbed a Visual Basic Function like this in the RDL.

Just to be clear, the purpose of the code shown in Listing 1 is to permit the developer to limit the number of rows during the "debug" phase of the report. Actually, there are other ways to solve this problem but the purpose of this article is to illustrate code-behind—and not in a Visual Basic (or C#) application subroutine but in a Reporting Services RDL report. That is, the actual code to be executed by the Report Processor at runtime. Yes, the code is re-interpreted each time the report is rendered.

RDL-based code-behind logic can be used for virtually any purpose and can be implemented in a variety of ways. In the following example, I'm going to illustrate how to place this code directly in the RDL (or RDLc) as a Report Property. In this case, the code returns a SQL string that's executed as a report data set. Yes, this code must be Visual Basic, not C#. And yes, it's possible to create compiled DLLs that contain other .NET executables in other languages, but getting them to work is a bit more complex. I'll leave that discussion for another article.

Preparing the Datasets

Now, it's time to get started. Don't even think about using Visual Studio 2008 for this project—not until SP1 as the Business Intelligence (BI) tools are not ready.

  1. Create a new BI Report Project in VS2005. No, don't choose the Report Project Wizard—not this time.
  2. Add a new Shared Data source by right-clicking the tab in the solution explorer. Fill in the Connection String or use the wizard to create one. In this case, I'll connect to the AdventureWorks example database that can be installed from the SQL Server 2005 setup disk.
  3. Figure 1: Building a Connection String

  4. Add a report to the project. Sure, if you have a custom template, this is when you can add it to the project. I often make this recommendation to customers who have a specific report style in mind. You can launch the Add New Report wizard (again) at this point if you're unsure about how to build a report from scratch. Most of the time, you won't—you'll steal (er, "leverage") an existing report as a starting point.
  5. Figure 2: Adding a report to the project.

  6. Because the purpose of this article is not authoring reports, I'm going to assume you can set up a basic report against the AdventureWorks Products table. For the initial query, you're going to create a parameter query to limit rows to products that returns selected columns based on a chosen Product Style and Class columns. Boring, but easy to set up and illustrate a few points. Listing 2 shows the SQL generated by the Query Builder as shown in Figure 3.
  7. Note: It's okay to cheat when creating the actual query—I suggest using SQL Server Management Studio's query designer to code and debug the query. That's because Visual Studio (even 2008) still does not return informative SQL syntax exception information. I just pasted the result into the Query Designer dialog when I was satisfied it was returning the right rowset.
    SELECT Name, Color, StandardCost, ListPrice, Style, Class
    FROM   Production.Product
    WHERE  (Style = @prmStyleWanted) AND _
           (Class IN (@prmClassWanted))
    

    Listing 2: SQL generated by the Query Builder.



    Click here for a larger image.

    Figure 3: Building the Dataset query with the Graphical Query Designer.

    Tip: Click the Refresh button to populate the Dataset explorer window with the columns returned by the query.

Go to page: 1  2  3  Next  


Tools:
Add www.developer.com to your favorites
Add www.developer.com to your browser search box
IE 7 | Firefox 2.0 | Firefox 1.5.x
Receive news via our XML/RSS feed


Database Archives

Intel Go Parallel Portal: Translating Multicore Power into Application Performance
Whitepaper: XML Processing in Applications--Take the Next Step
Whitepaper: Embeddable Content Platform for OEM's
Data Sheet: IBM Information Server Blade
Flash Demo: Learn how IBM Information Server Blade is easy to manage, highly scalable and efficient.



JupiterOnlineMedia

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info


Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

Solutions
Whitepapers and eBooks
Microsoft Article: HyperV-The Killer Feature in WinServer ‘08
Avaya Article: How to Feed Data into the Avaya Event Processor
Microsoft Article: Install What You Need with Win Server ‘08
HP eBook: Putting the Green into IT
Whitepaper: HP Integrated Citrix XenServer for HP ProLiant Servers
Intel Go Parallel Portal: Interview with C++ Guru Herb Sutter, Part 1
Intel Go Parallel Portal: Interview with C++ Guru Herb Sutter, Part 2--The Future of Concurrency
Avaya Article: Setting Up a SIP A/S Development Environment
IBM Article: How Cool Is Your Data Center?
Microsoft Article: Managing Virtual Machines with Microsoft System Center
HP eBook: Storage Networking , Part 1
Microsoft Article: Solving Data Center Complexity with Microsoft System Center Configuration Manager 2007
MORE WHITEPAPERS, EBOOKS, AND ARTICLES
Webcasts
Intel Video: Are Multi-core Processors Here to Stay?
On-Demand Webcast: Five Virtualization Trends to Watch
HP Video: Page Cost Calculator
Intel Video: APIs for Parallel Programming
HP Webcast: Storage Is Changing Fast - Be Ready or Be Left Behind
Microsoft Silverlight Video: Creating Fading Controls with Expression Design and Expression Blend 2
MORE WEBCASTS, PODCASTS, AND VIDEOS
Downloads and eKits
Sun Download: Solaris 8 Migration Assistant
Sybase Download: SQL Anywhere Developer Edition
Red Gate Download: SQL Backup Pro and free DBA Best Practices eBook
Red Gate Download: SQL Compare Pro 6
Iron Speed Designer Application Generator
MORE DOWNLOADS, EKITS, AND FREE TRIALS
Tutorials and Demos
How-to-Article: Preparing for Hyper-Threading Technology and Dual Core Technology
eTouch PDF: Conquering the Tyranny of E-Mail and Word Processors
IBM Article: Collaborating in the High-Performance Workplace
HP Demo: StorageWorks EVA4400
Intel Featured Algorhythm: Intel Threading Building Blocks--The Pipeline Class
Microsoft How-to Article: Get Going with Silverlight and Windows Live
MORE TUTORIALS, DEMOS AND STEP-BY-STEP GUIDES