Importing ascii file into datatable

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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
 
You might be able to setup a datareader using the texfile driver
and then do an insert query from the textfile into your 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?

What is the format of the text file?


Paul ~~~ (e-mail address removed)
Microsoft MVP (Visual Basic)
 
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top