tags:

views:

65

answers:

1

i need to import a large tab deliminated text file with a lot of columns (over 50 columns) i would like to write a c# script that creates the table based on the header of the text file.

assume all fields are nvarchar(1000)

i cannot use any program such as sql data import wizard.

+1  A: 

You should use BCP, it'll be a lot quicker.

Eg like this:

BCP mydatabase.dbo.mytable in myfile.txt -t -S myserver -U login -P password

The only requirement is that the columns in your file match up to the columns in your table. But if they're all varchar(100) in your case then that should be easy.

-edit- Hang on, this'll only work if you've already created the table, this won't create a new table based upon the header row as i just noticed you said.

Chris
what is BCP....?
newbie
Here you go mate:http://msdn2.microsoft.com/en-us/library/ms162802.aspx
Chris
And here's how you'd use it to import a tab delimited file:BCP mydatabase.dbo.mytable in myfile.txt -t -S myserver -U login -P password
Chris