get column count of tab delimited file

  • Hi ,

    i have a package that reads data from a tab delimited file. i want to know if there is a way to check the column count of the tab delimited file before i upload it?

    tnx

  • Not hard with a script component. Here's a snippet - assumes variables declared and strFilepath, strFilename have been set:

    'Connect to the CSV file and open it

    strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" & _

    "Data Source=" & strFilepath & ";" & _

    "Extended Properties=""text;HDR=YES;FMT=Delimited"""

    objConn.ConnectionString = strConn

    objConn.Open()

    SelectCommand = "Select * from [" & strFilename & "]"

    objCmd = New OleDbCommand(SelectCommand, objConn)

    objSourceReader = objCmd.ExecuteReader

    objSourceReader.Read()

    numFields = objSourceReader.FieldCount

    etc etc

    Then just use numFields as you need ...

    --edit-- the conn string is for comma delimited - you may need to adjust for tab delimited.

    The absence of evidence is not evidence of absence
    - Martin Rees
    The absence of consumable DDL, sample data and desired results is, however, evidence of the absence of my response
    - Phil Parkin

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

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