Click here to Skip to main content
15,892,059 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I want to read data from a text file line by line and insert the data in each line in database.

What I'm thinking of now read line by line and at each line insert to database. What I'm asking here is there a better idea to do so? like what can we do to insert data at once instead of looping line by line and insert the record? I have around 500+ lines in the text file that I need to store each day, so performance is my issue here.
Posted
Updated 5-Dec-13 20:08pm
v2
Comments
JoCodes 6-Dec-13 2:03am    
Whats the code you tried?
[no name] 6-Dec-13 2:09am    
I didn't try yet, what I'm asking here is this a good idea? or is there a better idea to do so. my conceren is the performance since I have 500 lines in text file and I'm worry reading and inserting line by line may be slow...
JoCodes 6-Dec-13 2:14am    
Not seem to be a good idea. Each time should hit the DB for insert line by line...
JoCodes 6-Dec-13 2:18am    
Should consider reading the text file at once instead of line by line.
[no name] 6-Dec-13 2:29am    
ok if I read at once how to insert them in database? should I add the data are delimiter by comma so I need to split them and insert them on specific columns.

1 solution

It depends on your exact requirements.
If you need to store one line into one record (for instance, if required by later processing) then you have to insert line by line the text file (and probably it doesn't matter if you read the whole file once or not).
On the other hand if you are allowed to store the whole text file content into a database record then read the whole fine at once and just insert it into the database record.
 
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