MS SQL Server
  Home arrow MS SQL Server arrow Page 4 - Using Data Transformation Services: Captur...
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Mobile Linux 
App Generation ROI 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
MS SQL SERVER

Using Data Transformation Services: Capture Recordset with a Global Variable
By: Jayaram Krishnaswamy
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 8
    2005-09-20

    Table of Contents:
  • Using Data Transformation Services: Capture Recordset with a Global Variable
  • The Query on the Northwind database
  • Stuffing rowset into a global variable
  • Retrieve rowset using Activex Script

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Using Data Transformation Services: Capture Recordset with a Global Variable - Retrieve rowset using Activex Script


    (Page 4 of 4 )

    In this part, we will take a look at the Global variable Contacts created in the previous step using Activex Script. Pick up an Activex task and instantiate it on the design pane. As you click the Activex task in the tasks collection, an Activex icon is placed on the design pane, simultaneously opening the window to write your Activex Script as shown in the next screen. Please review my previous tutorials on the details about this window and its several controls.

    In this screen we declare an object RS and assign to it an ADODB.Recordset object created using the CreateObject() method. In the next line,  we associate this record set with a DTSGlobalVariable. Now it is easy to cycle through the recordset to look at its properties, such as the number of records, the various fields and their properties, and so on. This is what is being achieved in the For ...Next statement. The script used to retrieve the recordset and display in a MsgBox is shown here.

    '**************************************************************
    '  Visual Basic ActiveX Script
    '**************************************************************
    Function Main()
    dim cnt
    dim RS
    set RS = CreateObject("ADODB.Recordset")
    set RS = DTSGlobalVariables("Contacts").value
    for cnt = 1 to RS.RecordCount
    MsgBox ( "Contact Name: " & RS.Fields("ContactName").value _
    &" ; ContactTitle:  " & RS.Fields("ContactTitle").value _
    &" ; City : " & RS.Fields("City").value _
    &" ; Country:   " & RS.Fields("Country" ) & vbcrlf  )
    RS.MoveNext
    Next
    Main = DTSTaskExecResult_Success
    End Function
    
    Finishing up the DTS Package

    The package now contains an ExecuteSQLTask and an Activex Task. We want the Activex task to be processed after the ExecuteSQL task. We invoke the services of a Work Flow. Highlight both of the tasks and set up the work flow as shown here(review the previous tutorials for a more detailed explanation). We want the Source Step to succeed (complete is also acceptable) before the Destination step to be processed.

    Now, we will test this package. Save the package and from menu item Package's drop-down click on Execute. This runs the package. The result is shown in the next picture. The MsgBox will pop up seven times, each time bringing a row from the queries result set and finally a DTS message (Package Execution Results window) about the success of the run. The picture shows the first row in the message box.

    Summary

    Assigning records returned from SQL Queries to a global variable is described in detail. The record set was displayed using a message box, but using the powerful scripting support available in VBA, it is possible to take these into a variety of forms, text files, Excel spread sheets, and so forth.


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

       · Most of my tutorials on DTS deals with the usage of the DTS Designer. I am...
     

    MS SQL SERVER ARTICLES

    - Completing the Introduction to Transact-SQL
    - A Brief Introduction to Transact-SQL
    - Lookups and Blocking Bad Data
    - Field Validation Rules for Blocking Bad Data
    - Using Masks to Block Bad Data
    - Blocking Bad Data
    - Using @@ROWCOUNT and TABLE Variables for Dat...
    - How to Use Variables, IF and CASE in Databas...
    - Creating Important Aspects of Notification S...
    - Working wth Variables in Database Interactio...
    - Delving Deeper into Notification Services
    - Notification Services
    - Building a Multi-table Report with SQL 2005 ...
    - A Secure Way of Building Connection Strings
    - Transferring a Database Using the SSIS Desig...





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
    Stay green...Green IT