Click here to Skip to main content
15,883,825 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Dear friends,

I have a string variable with a data in csv format. for example:
C#
string cadena="";
cadena=
"ROYALL;0921269982;2014-02-28;4200.00
 BOSCH;025458855;2014-03-01;5000
 CELLPRODUCT;78984145445;2014-03-10;3000
"


I want to create and load a DataTable in c# with this information and if is possible
to add a header columns with this titles:

PROVIDER IDENTIFICATION_NUMBER  DATE  AMOUNT_INVOICE.


Please give me an example that i can do this.

Thanks in advance.

Leonardo Ayala R.
Posted
Updated 27-Feb-14 8:30am
v2

1 solution

All what you need is OleDb[^].

For further information, please see:
Reading Comma Delimited Files[^]
Setting Options Programmatically for the Text File Driver[^]
Schema.ini File (Text File Driver)[^]


[EDIT]
Sorry, my mistake.

There is nothing hard to do. You need to split string text by comma.
Have a look here:
How to: Split Strings (C# Programming Guide)[^]
and try!

Another, useful resources:
How to: Read From Comma-Delimited Text Files in Visual Basic[^]
Reading and Writing CSV Files in C#[^]

[/EDIT]
 
Share this answer
 
v3
Comments
leocode7 27-Feb-14 14:52pm    
Your solution it's for a txt file , I say from a string variable with csv text.
Maciej Los 27-Feb-14 15:01pm    
Check now ;)
leocode7 27-Feb-14 18:11pm    
Thanks my friend, I used split funtion to manage the string
variable with csv data.
Maciej Los 27-Feb-14 18:20pm    
You're welcome ;)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900