简体   繁体   中英

How to remove empty rows using SSIS tools from a flat file source?

I'm trying to remove all empty rows from my flat file in SSIS. I tried using Conditional Split to resolve this problem, but that solution is not the best option for the task I'm working on. I was wondering is there any C# code that will delete all empty rows that I can use in Script Component? I'm new with SSIS and c#, so any help would be appreciated.

Here's some C# to help you out. You aren't very clear about what a null row means:

This will work a script component and will let you work with the non empty row:

using System.IO; //This gets you to File (Way up top with the rest of the usings)

public static void Main()
{
    string path = @"c:\[where ever you file is located].txt";

    // Check path.
    if (File.Exists(path))
    {
        string[] lines = File.ReadAllLines(path);

       foreach(string line in lines)
       {
         if(!string.IsNullOrEmpty(line)) //Not null or empty
         {
              //[DO STUFF -- use split if you want to go to data flow]
         }
       }
    }
}

In case your flat file source is Excel, try the approach outlined in the following link.

https://devjef.wordpress.com/2014/02/05/ssis-remove-empty-rows-from-excel-import/

You mentioned that the conditional split is not the best approach, but did not state why. Perhaps the above will help verify that you're applying it correctly, since you are new to SSIS.

Hope this helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM