Link to home
Start Free TrialLog in
Avatar of choochim
choochim

asked on

Importing ASCII text files to SQL via web (ASP.Net)

Can some web guru enlighten me as to how to pull in an ascii text file into a sql server table? The file will be uploaded by the user via web form.
Avatar of jsbhatia
jsbhatia

You can use the BCP utility to import data from an ascii file into a database.
More info about bcp can be found at:

http://msdn.microsoft.com/en-us/library/aa174646.aspx
http://asptutorials.net/SQL-Server/sseutil-and-database-replication/
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=112482
Avatar of choochim

ASKER

I need to use standard sql to do this task as I do not have access to BCP utility on server. Besides, the file is going to be uploaded via ASP.Net web page by the user. I need to process it once it has been uploaded and insert the records into the SQL DB. Hope this makes it a bit clear.
Youcan use FileUpload control in asp .net 2.0 to upload file to the server. Once uploaded, you will have the path on the server where you have saved the file. Use StreamReader to load the uploaded file and run a loop to read one line at a time and create the query to insert in the database. Alternatively, you can also use File.ReadAllLines, which will return the array of lines as string, then run a loop for that array.length, create query to insert

To upload a file, check out

http://msdn.microsoft.com/en-us/library/aa479405.aspx
ASKER CERTIFIED SOLUTION
Avatar of EugeneZ
EugeneZ
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
EugeneZ:

I am talking about good old ASCII text files with some delimited data. I need each line of this text file to be inserted as rows to a SQL table on SQL Server.