>>I am using bulk insert to insert records from a flat pipe delimited file to a table. Here is the script I am using:
>>
>>
>>BULK INSERT
>> MyTable
>>FROM
>> 'c:\MyFile.txt'
>>WITH
>>(
>> FIELDTERMINATOR = '|'
>> , ROWTERMINATOR = '|\n'
>> , FIRSTROW = 2
>>)
>>
>>
>>I have two questions:
>>First, is there a way to avoid the rows being index based? Is there way to use the column header to determine what field the element belongs in, instead of just skipping the row like I am in the example?
>>
>>Second (and this might be related to the first question), is there a way to include an auto-incrementing PK field?
>
>Mike,
>I didn't understand your first question.
>Second, auto inc PK is part of the table itself and thus would auto populated.
>
>I don't know if it were you who asked a similar question recently, if not check SqlBulkCopy class. It is easier to use, much more flexible and IMHO as fast as bulk insert (or faster).
>Cetin
Cetin,
My requirement is to have the loading logic in a Stored Procedure, so that's why I am using Bulk Insert.
Regarding my first question, the more I think about it, the more I don't need it. Disregard.
The second question is still valid though. When I add the ID field, it fails because it attempts to insert my first column value from my file into that field, instead of autoinc.