data transfer from flatfile to database using C# coding

  • Hi All,

    My Requriement :

    1. Source Data is on Flat File with 1000 records on each file and i have 20 Files

    2. Destination is SQL Server 2008 Database.

    3. How to Insert only last 10 records from a file to SQL Server database.

    We can do this with the Script Task T/F but i need to use C# or dotnet coding.

    Could you please provide me the steps.

    Please let me know if you are not clear on my question.

    Thanks

  • Are they fixed width files or delimited?

    If fixed you can seek to the end of the file and then seek back this number of bytes:

    10 * ([bytes in each row] + [bytes in each line break])

    Reading "the last n rows of a delimited file" is a tricky problem. Files are sequential by nature so while you're reading the file there is no real way to know if you're on the n-th to last row of the file unless it's fixed width.

    One possible solution:

    1) Extract the last 10 rows of the file into a new file using tail.exe in the Windows Server 2003 Resource Kit Tools

    2) Load the new file into SQL Server using a standard Data Flow Task.

    Another:

    1) Re-invent the wheel and implement a Script Task to extract the last 10 rows of the file to a new file. Advantage: no external dependency. Disadvantage: another wheel. If you want the actual C# code to see here: http://tinyurl.com/425xdbj

    2) Same as first possible solution above.

    There are no special teachers of virtue, because virtue is taught by the whole community.
    --Plato

  • thanks a lot....

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

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