loading stream into datatable.

  • Thread starter Thread starter Archana
  • Start date Start date
A

Archana

Hi all,

I want to load content into datatable which are in CSV file format.

What i am doing is reading one text file which is in csv format into
string.

Later on i want this string to be in datatable.

Can i bind strring content to datatable?

Please help me asap.

thanks in advance.
 
Archana,

You can use the OleDb provider to work with text files.

You might want to google for: OleDb text file datatable

Kerry Moorman
 
hi,

thanks for reply.

But i don't have any text file.

Runtime i am creating content to be loaded into datatable. And oledb
require filename to be specify before loading.

so please help me if i can load content dynamically into datatable.


thanks.
 
Archana,

Sure. Just create the datatable with appropriate columns in code and add
your data as rows to the datatable.

Kerry Moorman
 
Archana,

Some call a csv file a textfile some call it a csv file, however a csv file
is nothing more than a comma seperated text file. Be aware that comma is a
litle bit misleading, because in most culture settings it is ";".

A sample with OleDB for that.
http://www.vb-tips.com/CSVDataSet.aspx

Cor
 
hi,

thanks for reply,.

but i want complete string into datatable and now row by row. Means
say i have string in csv format and i want to load that into
datatable.

how will i do this?

thanks.
 
Ah, you've been told how several times at this point. Here it is again:

Start by defining a DataTable and add DataColumn instances for each column
to the Columns collection.

Take the string, parse it into columns, create a new DataRow,
populate it with the data from the parsed string and add the row to the
DataTable Rows collection.

This does not save it anywhere...

--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant, Dad, Grandpa
Microsoft MVP
INETA Speaker
www.betav.com
www.betav.com/blog/billva
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________
Visit www.hitchhikerguides.net to get more information on my latest book:
Hitchhiker's Guide to Visual Studio and SQL Server (7th Edition)
and Hitchhiker's Guide to SQL Server 2005 Compact Edition (EBook)
 
hi,

thanks for reply.

I think you are not getting my question.. I want logic for parsing
that string only. Means how to parse string having CSV format. Some
logic or algorithm to parse csv content.

I hope u can understand it now.

thanks.
 
Archana,

You can start with String.Split.

If that does not work for your particular csv string then you can next try
RegEx.Split.

If that does not work for your particular csv string then you will need to
write your own parser that walks the characters of the string and makes
decisions on when a complete field has been retrieved, etc.

Kerry Moorman
 
Archana,

We eat mostly through our mouth, we don't use other open parts of our body
for that, the same is it with reading into a datatable.

(In Dutch I would have said this in an other way)

:-)

Cor
 
Back
Top