dcsimg
Results 1 to 4 of 4

Thread: [RESOLVED] Fixed width file reader for SQLBulkCopy

  1. #1

    Thread Starter
    Fanatic Member cory_jackson's Avatar
    Join Date
    Dec 2011
    Location
    Fallbrook, California
    Posts
    896

    Resolved [RESOLVED] Fixed width file reader for SQLBulkCopy

    I want to read fixed-width text file using the SqlBulkCopy class. One method I see is to create a DataTable object and populate it, but I saw some examples online that suggest it can also use an iDataReader object as source. Is there a way I can use an object like TextFieldParser to skip creating the table object? Or some other kind of reader or do I always need to create a table or list of Row objects?

  2. #2
    Frenzied Member ChrisE's Avatar
    Join Date
    Jun 2017
    Location
    Frankfurt
    Posts
    1,993

    Re: Fixed width file reader for SQLBulkCopy

    Hi

    this is for a csv you would have to adjust it to a Fixed with File

    Code:
    https://blog.netnerds.net/2015/01/powershell-high-performance-techniques-for-importing-csv-to-sql-server/
    to hunt a species to extinction is not logical !
    since 2010 the number of Tigers are rising again in 2016 - 3900 were counted. with Baby Callas it's 3901, my wife and I had 2-3 months the privilege of raising a Baby Tiger.

  3. #3

    Thread Starter
    Fanatic Member cory_jackson's Avatar
    Join Date
    Dec 2011
    Location
    Fallbrook, California
    Posts
    896

    Re: Fixed width file reader for SQLBulkCopy

    Nice quote from Spock. Love that movie.

    The example on the site you cite uses an intermediary data table, I know how to do that. I was wondering if it could be done without creating a table.
    I have something I'm going to try Monday. I'll post if I have any success.

  4. #4

    Thread Starter
    Fanatic Member cory_jackson's Avatar
    Join Date
    Dec 2011
    Location
    Fallbrook, California
    Posts
    896

    Re: Fixed width file reader for SQLBulkCopy

    I made a test program and the SQLBulkCopy object will not accept a TextFieldParser as a source in the WriteToServer method. It appears to me one must create a table object in memory for this to work.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width