473,511 Members | 16,756 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Importing ascii file into datatable

I want to create a datatable from a text file.
Currently I open the file as a textstream and read one line at a time.
After reading each line I create a new row for my table and parse the line to
set the value for each item in my datarow. Then I add the datarow to the
datatble.
This works fine but is too slow.
I was looking for a way to import an ascii text file directly to a datatable
similar to the way you import into an excel spreadsheet where you define
fixed widths or some field seperator and then import the whole file in one
shot instead of line by line.
So far I haven't been able to find any bulk import method.
Any suggestions?

Regards,
Erik
Nov 21 '05 #1
4 3647
You might be able to setup a datareader using the texfile driver
and then do an insert query from the textfile into your datatable.

"Engineerik" <En********@discussions.microsoft.com> wrote in message
news:AB**********************************@microsof t.com...
I want to create a datatable from a text file.
Currently I open the file as a textstream and read one line at a time.
After reading each line I create a new row for my table and parse the line to
set the value for each item in my datarow. Then I add the datarow to the
datatble.
This works fine but is too slow.
I was looking for a way to import an ascii text file directly to a datatable
similar to the way you import into an excel spreadsheet where you define
fixed widths or some field seperator and then import the whole file in one
shot instead of line by line.
So far I haven't been able to find any bulk import method.
Any suggestions?

Regards,
Erik

Nov 21 '05 #2
Check out www.connectionstrings.com there's a connectionstring there for the
OleDbDataAdapter that should do it for you.

--
W.G. Ryan MVP (Windows Embedded)

TiBA Solutions
www.tibasolutions.com | www.devbuzz.com | www.knowdotnet.com
"Engineerik" <En********@discussions.microsoft.com> wrote in message
news:AB**********************************@microsof t.com...
I want to create a datatable from a text file.
Currently I open the file as a textstream and read one line at a time.
After reading each line I create a new row for my table and parse the line to set the value for each item in my datarow. Then I add the datarow to the
datatble.
This works fine but is too slow.
I was looking for a way to import an ascii text file directly to a datatable similar to the way you import into an excel spreadsheet where you define
fixed widths or some field seperator and then import the whole file in one
shot instead of line by line.
So far I haven't been able to find any bulk import method.
Any suggestions?

Regards,
Erik

Nov 21 '05 #3
On Thu, 6 Jan 2005 13:05:03 -0800, "Engineerik" <En********@discussions.microsoft.com> wrote:

¤ I want to create a datatable from a text file.
¤ Currently I open the file as a textstream and read one line at a time.
¤ After reading each line I create a new row for my table and parse the line to
¤ set the value for each item in my datarow. Then I add the datarow to the
¤ datatble.
¤ This works fine but is too slow.
¤ I was looking for a way to import an ascii text file directly to a datatable
¤ similar to the way you import into an excel spreadsheet where you define
¤ fixed widths or some field seperator and then import the whole file in one
¤ shot instead of line by line.
¤ So far I haven't been able to find any bulk import method.
¤ Any suggestions?

What is the format of the text file?
Paul ~~~ pc******@ameritech.net
Microsoft MVP (Visual Basic)
Nov 21 '05 #4
Eric,

When your file is a kind of csv you can use the oledbadapter and the
dataset.

In my opinion when it is a flat file, it has not much sense. Don't expect
that your reading will cost less time using the oledbadapter. That
dataadapter would have to read it as well.

Just my thought,

Cor
Nov 21 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
4574
by: Thomas R. Hummel | last post by:
Hello, I am importing a file using BCP, with a format file. It is a fixed-width file, which I am importing into a table that has a column for each field in the file. The columns in my import...
7
3287
by: Timothy Shih | last post by:
Hi, I am trying to figure out how to use unmanaged code using P/Invoke. I wrote a simple function which takes in 2 buffers (one a byte buffer, one a char buffer) and copies the contents of the byte...
1
2452
by: Luis Esteban Valencia | last post by:
Hello Everyone, Iam an intermediate ASP.Net programmer and iam facing a challenging task. I have a table in MS-SQL server database called 'Members'. The table has following fields... ...
3
8911
by: Conrad F | last post by:
Hello All, I know how to import a specific named excel sheet into a datagrid using ADO.NET by setting up a JET connection and then SELECTing data from the sheet. However, for a real world...
1
2041
by: BobLaughland | last post by:
What is the best way to import the contents of a CSV file into C# objects? E.G. a CSV file that looks like this a1,b1,c1,d1, a2,b2,c2,d2, a3,b3,c3,d3 Would be loaded up and then turned...
0
1501
by: Mike Collins | last post by:
I am trying to export data from multiple tables in SQL Server to an XML file so I can then import it to another database. It seems to be working fine for exporting, but I am having trouble...
5
2158
by: Mike Collins | last post by:
I am trying to export data from multiple tables in SQL Server to an XML file so I can then import it to another database. It seems to be working fine for exporting, but I am having trouble...
0
1470
by: Mike Collins | last post by:
I am importing a XML file and have not been having the best of luck in doing this, but I do have the following solution below. I will not be importing more than 2000 records at a time, but will be...
0
2988
by: Anish G | last post by:
Hi All, I am getting the below given error while running my application in live server. In my local machine, its working fine. Please help me as it is very urgent for me. Exception from...
0
7242
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7138
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7355
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7423
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7081
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
4737
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3225
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1576
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
781
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.