Lesson 1: Creating the RDL Generator Visual Studio Project

For this tutorial, you will create a simple console application. This tutorial assumes that you are developing in Microsoft Visual Studio.

To create a console application

  1. On the File menu, point to New, and then click Project to open the New Project dialog box.

  2. Expand either the Visual Basic Projects or the Visual C# Projects folder.

  3. Click the Console Application icon.

  4. In the Name box, enter a name for your project. Type the name SampleRDLGenerator.

  5. In the Location box, enter the path where you want to save your project, or click Browse to navigate to the folder.

  6. Click OK. A collapsed view of your project appears in Solution Explorer.

    In Solution Explorer, expand the project node. A code file with the default name of Program.cs (Module1.vb for Visual Basic) has been added to your project.

When you have finished creating the application template, replace the contents of the code file with the following:

Imports System
Imports System.Collections
Imports System.Data
Imports System.Data.SqlClient
Imports System.IO
Imports System.Text
Imports System.Xml

Namespace SampleRDLGenerator
   Class RdlGenerator
      Private m_connection As SqlConnection
      Private m_connectString As String
      Private m_commandText As String
      Private m_fields As ArrayList
      
      
      Public Shared Sub Main()
         Dim myRdlGenerator As New RdlGenerator()
         myRdlGenerator.Run()
      End Sub 'Main
      
      
      Public Sub Run()
         Try
            ' Call methods to create the RDL
            Me.OpenConnection()
            Me.GenerateFieldsList()
            Me.GenerateRdl()
            
            Console.WriteLine("RDL file generated successfully.")
         
         Catch exception As Exception
            Console.WriteLine(("An error occurred: " + exception.Message))
         
         Finally
            ' Close the connection string
            m_connection.Close()
         End Try
      End Sub 'Run
      
      
      Public Sub OpenConnection()
      End Sub 'OpenConnection
      
      ' TODO: Open a connection to the sample database
      
      Public Sub GenerateFieldsList()
      End Sub 'GenerateFieldsList
      
      ' TODO: Generate a list of fields for a report query
      
      Public Sub GenerateRdl()
      End Sub 'GenerateRdl
   End Class 'RdlGenerator ' TODO: Generate RDL using XmlTextWriter
End Namespace 'SampleRDLGenerator
using System;
using System.Collections;
using System.Data;
using System.Data.SqlClient;
using System.IO;
using System.Text;
using System.Xml;

namespace SampleRDLGenerator
{
   class RdlGenerator
   {
      SqlConnection m_connection;
      string m_connectString;
      string m_commandText;
      ArrayList m_fields;

      public static void Main()
      {
         RdlGenerator myRdlGenerator = new RdlGenerator();
         myRdlGenerator.Run();
      }

      public void Run()
      {
         try
         {
            // Call methods to create the RDL
            this.OpenConnection();
            this.GenerateFieldsList();
            this.GenerateRdl();

            Console.WriteLine("RDL file generated successfully.");
         }

         catch (Exception exception)
         {
            Console.WriteLine("An error occurred: " + exception.Message);
         }

         finally
         {
            // Close the connection string
            m_connection.Close();
         }
      }

      public void OpenConnection()
      {
         // TODO: Open a connection to the sample database
      }

      public void GenerateFieldsList()
      {
         // TODO: Generate a list of fields for a report query
      }

      public void GenerateRdl()
      {
         // TODO: Generate RDL using XmlTextWriter
      }
   }
}