loading stream into datatable.

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.
 
G

Guest

Archana,

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

You might want to google for: OleDb text file datatable

Kerry Moorman
 
A

Archana

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.
 
G

Guest

Archana,

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

Kerry Moorman
 
C

Cor Ligthert[MVP]

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
 
A

Archana

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.
 
W

William Vaughn

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)
 
A

Archana

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.
 
G

Guest

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
 
C

Cor Ligthert[MVP]

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
 

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

Top