Hi Friends
I need to do bulk insert from textfile into datatable using c# without using loops..is there any possibilities to do? if it is kindly let me know with c# code.
thanks in advance for your help
Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Jaganathan BantheswaranRank #170 · 14.1K reputationPosted Mar 18, 2011, 5:29 AM EDT
You can.
Use StreamReader class.
string bulkData=string.Empty;
using(StreamReader sr = new StreamReader("path to text file"))
{
bulkData = sr.ReadToEnd();
}
update the bulkData value in DB now.
Rajesh S108 reputationPosted Mar 18, 2011, 5:35 AM EDT
I need to insert into datatable because i have more than 1000 rows in text file..kindly let me know.
thanks in advance
Jaganathan BantheswaranRank #170 · 14.1K reputationPosted Mar 18, 2011, 5:50 AM EDT
Yes. you can
The limit of the string length depends only on the amount of memory available.
I tried to create a string with 2.147.483.647 characters, but around
50.000.000 characters my system can't handle it anymore. That's only 2% of
it...
So if you have memory capacity to read that much data at a time [ Bulk ] this code will work
Rajesh S108 reputationPosted Mar 18, 2011, 6:38 AM EDT
Is there any posibilities to directly insert into datatable because however finally i need to insert records into datatable so that i am asking.
Thanks in advance
Suthish NairRank #92 · 22.8K reputationPosted Mar 18, 2011, 7:33 AM EDT
Suthish NairRank #92 · 22.8K reputationPosted Mar 18, 2011, 7:35 AM EDT