Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to import a Tab Delimited Text File...

Status
Not open for further replies.

sqlsamurai

Programmer
May 11, 2005
120
US
I want to be able to import a Tab demlimited text file into a table in SQL Server.

My first instinct was write a small .NET app that would import the text file into a datatable then add the records in the datatable into the table in SQL Server.

I have looked all over the internet and cant seem to find an example of importing a tab delimited file and then adding the imported records into a table in a database.

Then i thought it might be easier to create a job or a dts job and just run that on demand from my .NET app. Not sure which one would be the best approach.

Does anybody have any advice?
 
Well, this really isn't the forum. You really want one of the SQL forums.


HOWEVER, take a look at the SQL Server tasks. What version of SQL Server? Open your db, open the tables. Right click on the table name, go to either All Tasks-> import or simply the import task. Go from there. It's pretty easy to use.
 
I'm sorry if i was unclear. I want to use VB .NET to import the text file and then to write it to SQL Server. I want to do it this way because I'm writing an app for an end-user that will be performing this import/add on demand.

Thanks anyway.
 
In that case, you can use the Microsoft Text Driver to import the tab delimited file into a DataTable, then loop through each row and insert them into SQL Server.

You may also be able to use a DataAdaptor instead and do the insert that way.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
The sql-servers bulk insert command will do an even better job and much faster.

Christiaan Baes
Belgium

"Time for a new sig." - Me
 
You will also need code to take into account badly formatted data, such as blank fields, data that is too long, nor enough fields, etc.

This may not be a big deal if the file you import isn't very big, but if it's large, and the program dies in the middle of the import, someone will have to go and look at the data and figure out what the problem is.

You may also want to run a DTS package thru vb net. Doa google search on dts vb net. There is a ton of info on how to do it. Once you have your DTS package set up and running, it shouldn't be a big deal to run it in vb net. And you should be able to log any problems to a exception log in vb.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top