• tush002sunny (9/21/2015)


    Hi,

    I'm stuck with the thing where I don't know what to use for reading count in header of .csv file as source and compare it with acutal number of records within that file.

    If this comaprison is successful, I want to load that data from CSV file into a sQL table.

    I tried using Script component for validation, but no luck as of now.

    Can someone please suggest with solution?

    Thanks inadvance !!

    Sunny,

    What do you mean by "reading count in header of .csv file"? Do you mean "Number of header columns" in a .csv file? If that so, use can do it using script task.

    How many columns does your valid file contains?

    The code below will count the no of columns from the source file. This code is in C#.

    String sColnames = Dts.Variables["User::COLUMN_NAMES"].Value.ToString();

    String sFilePath = Dts.Variables["User::FILEPATH"].Value.ToString();

    using (StreamReader sr = new StreamReader(sFilePath))

    {

    String Column_Names = sr.ReadLine();

    var TotalCols = Column_Names.Split(',').Length;

    if (TotalCols == 21) //21 = valid header column count,give your valid header count.

    {

    Dts.Variables["ValidFlag"].Value = 1;

    //MessageBox.Show(Dts.Variables["ValidFlag"].Value.ToString());

    }

    else

    {

    Dts.Variables["ValidFlag"].Value = 0;

    //MessageBox.Show(Dts.Variables["ValidFlag"].Value.ToString());

    }

    }