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.
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
To upload a file, check out
http://msdn.microsoft.com/en-us/library/aa479405.aspx
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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.
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.
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