Click here to Skip to main content
15,918,808 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi everyone,
I have a task where I have to upload a .txt file and then read from the file and insert the data into a database table. The file doesn't have delimiters, instead it has set lengths (eg. one field is 20 chars long, another is 2 chars long).
I don't have too much experience uploading/manipulating files like this, so any advice would be great. :)

Thanks in advance.
Posted

Why have you been given this task if you have no experience in doing it ? The part that always upsets me, is that most of the time, this means someone with no skills is being paid to do a job that should go to an experienced programmer.

If they are fixed size, then it's even easier. File.ReadAllLines will read your file into an array of strings. The Substring method of the string class will let you chop up your string into sections. Then you just take those variables and put them in the database.
 
Share this answer
 
Comments
toroole 12-Jul-10 17:00pm    
You're quick to assume I am getting paid. I am in fact a student just trying to learn from other's experiences.
Check out the SQL Zone[^] for some starter articles.
 
Share this answer
 
Hi there,

In my personal opinion, the method that Christian suggested is absolutely fine for files which do not have a large number of records or you do not care much about performance.

Since you are a student, if you have time, I would suggest looking into bulk inserting data into database.

For example , if your database backend is SQL Server , have a look at SMO (2005/08) or DMO (2000)


Regards
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900