Dundas Data Visualization Support Site
Dundas Support Site Home  |  Contact Us  |  Dundas Home  
Contact Us via Email
Home

Adding Symbols from a database in Dundas Map for Reporting Services

 

In Dundas Map for Reporting Services, the data fields that you can set in the report designer allow you to bind fields from your database to shapes, paths or symbols that you have already loaded into Dundas Map. You can add these elements (shapes, paths, etc.) by right-clicking the map and choosing Import Shapefiles or by adding symbols in the map control's Symbols collection (in the Map Designer's Advanced tab.)

You can also add symbols to the map directly from your database using Dundas Map's code editor:

  1. First, we need a query that will return a usable dataset. You can place symbols either by geographic coordinates (longitude and latitude) or by parent shape. Note that longitude is represented by an "X" coordinate in Dundas Map where West is a negative value, and latitude is represented by an "Y" coordinate in Dundas Map where South is a negative value. If you place a symbol using a parent shape, the symbol will be placed in the center of the shape that you name. The parent shape must already be imported into Dundas Map.

    Your query should return rows of data with a column representing the symbol's name and placement (either by coordinates or parent shape.)

  2. Now, we will add code:
    • In the report designer's Layout mode, right-click on the map control and choose View Code.
    • In the second drop-down, select the language of your choice, either VB.NET or C#. (Sample code is provided below in both languages.)
    • In the first drop-down menu, choose the run-time event when your code should execute. The PostInitialize event will work for our case.
    • Paste in your code. The following code connects to a Microsoft SQL Server database, but you can also use System.Data.OleDb.OleDbConnection, OleDbCommand and OleDbDataReader objects instead of the System.Data.SqlClient objects to connect to a different type of database:
      [C#]
      try
      {
          string connectionString = "** Provide your own connection string **"; 
          string queryString = "** Provide your own query string **"; 
      
          System.Data.SqlClient.SqlConnection connection = new System.Data.SqlClient.SqlConnection(connectionString); 
          System.Data.SqlClient.SqlCommand command = new System.Data.SqlClient.SqlCommand(queryString, connection); 
          command.Connection.Open(); 
          System.Data.SqlClient.SqlDataReader reader = command.ExecuteReader(); 
      
          // ** Modify the column names used ** 
          mapObj.DataBindSymbols(reader, "", "NameColumn", "", "XCoordinateColumn", "YCoordinateColumn");
      
          // Optional: Enable text labels to display for each symbol
          foreach(Symbol symbol in mapObj.Symbols)
          {
              symbol.Text = "#NAME";
          }
      }
      catch (Exception ex)
      {
          System.IO.File.WriteAllText("C:\\MapRSExceptionText.txt", ex.Message + "\n\n" + ex.StackTrace);
      }
      [VB.NET]
      Try
          Dim connectionString As String =  "** Provide your own connection string **" 
          Dim queryString As String =  "** Provide your own query string **" 
       
          Dim connection As System.Data.SqlClient.SqlConnection =  New System.Data.SqlClient.SqlConnection(connectionString) 
          Dim command As System.Data.SqlClient.SqlCommand =  New System.Data.SqlClient.SqlCommand(queryString,connection) 
          command.Connection.Open() 
          Dim reader As System.Data.SqlClient.SqlDataReader =  command.ExecuteReader() 
       
          ' ** Modify the column names used ** 
          mapObj.DataBindSymbols(reader, "", "NameColumn", "", "XCoordinateColumn", "YCoordinateColumn")
       
          ' Optional: Enable text labels to display for each symbol
          Dim symbol As Symbol
          For Each symbol In mapObj.Symbols
              symbol.Text = "#NAME"
          Next
      Catch ex As Exception
          System.IO.File.WriteAllText("C:\\MapRSExceptionText.txt", ex.Message + "\n\n" + ex.StackTrace)
      End Try
    • Set the connection and query strings in your code. Here is an example of how to easily find a connection string to use: if the database you want to connect to is already accessed by your report, go to the report's Data tab, click on "Edit Selected Data Set" from the toolbar, click on the "..." button next to your data source, and if the string is not available here, click on the "Edit" button next to your shared data source reference. You can copy and paste this into the code that assigns the connectionString within the double-quotes.

    • Set the column names used in the DataBindSymbols() method call to match the names returned by your query. If you want to bind your symbols to a parent shape, replace "XCoordinateColumn", "YCoordinateColumn" with a single "ParentShapeColumn".

    • Before running your report, click the "Compile" button at the top of our code editor and make sure "Compiled OK" is displayed at the bottom.

  3. Now preview your report! If the symbols do not appear as red dots:
    • Make sure that the coordinates in your database are within the coordinates displayed by Map - if you have loaded a map of India, only symbols in the area of India will be displayed.
    • Check if an exception occurred by looking for the file C:\MapRSExceptionText.txt. If it exists, check the message in the text file and change your connection, query or column names to fix the problem.

PoorExcellent