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.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Suthish NairPosted Mar 18, 2011, 11:35 AM
Suthish NairPosted Mar 18, 2011, 11:33 AM
Rajesh SPosted Mar 18, 2011, 10:38 AM
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
Jaganathan BantheswaranPosted Mar 18, 2011, 9:50 AM
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 SPosted Mar 18, 2011, 9:35 AM
I need to insert into datatable because i have more than 1000 rows in text file..kindly let me know.
thanks in advance
Jaganathan BantheswaranPosted Mar 18, 2011, 9:29 AM
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.