Get count of rows from a flat file source

  • I'm converting a DTS package to SSIS. Part of the processing of the package needs to check the row counts of flat files being imported via a Data Flow task and compare them with the row counts of their destination tables. I have a table setup that contains the allowed variance in percentage, it is different for each table. Basically, if table A has a row count of 12,000 and the file for table A has a row count of 11,543 and the variance value is set at 20% then it would allow the import of the data. However if the file row count was 8,000 or say 15,000 it would not.

    In DTS I did this in an ActiveX task, setting the file to be the source of an ADO Connection object. I then did a select count on it and stuffed that into a variable to be compared with the row count of the table.

    So far I don't know what I should use in SSIS. I know I can do the exact same thing the DTS did in a Script task using vb.net. But it seems that there must be an easier/better way to handle this. Any suggestions out there?

    Thanks in advance!

    Jake Carter

  • Thought I'd post what I came up with, may not be the best method, but it works.

    Code from Script Task:

    Private Function GetFileRowCount(ByVal ImportFile_Path As String) As Long

       Dim LineCount As Long

       Dim sr As System.IO.StreamReader

       Dim str As String

       Dim i As Long

     

       Try

           sr = New System.IO.StreamReader(ImportFile_Path)

     

           Do

               str = sr.ReadLine

     

               If Not str Is Nothing Then

                   If str.Length > 1 Then

                       LineCount += 1

                   End If

                  str = String.Empty

               End If

     

           Loop Until str Is Nothing

           sr.Close()

           sr = Nothing

           Return LineCount

       Catch ex As Exception

           Throw ex

       End Try

     

    End Function

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply