如何使用c#中的csv数据加载带有字符串变量的DataTable [英] How Load DataTable with a string variable with csv data in c#
本文介绍了如何使用c#中的csv数据加载带有字符串变量的DataTable的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
亲爱的朋友们,
我有一个字符串变量,其中包含csv格式的数据。例如:
Dear friends,
I have a string variable with a data in csv format. for example:
string cadena="";
cadena=
"ROYALL;0921269982;2014-02-28;4200.00
BOSCH;025458855;2014-03-01;5000
CELLPRODUCT;78984145445;2014-03-10;3000
"
我想在c#中使用这些信息创建和加载DataTable,如果可能的话,
添加带有此标题的标题列:
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.
请举个例子说明我可以这样做。
提前致谢。
Leonardo Ayala R.
Please give me an example that i can do this.
Thanks in advance.
Leonardo Ayala R.
推荐答案
所有你需要的是 OleDb [ ^ ]。
如需了解更多信息,请参阅:
读取逗号分隔文件 [ ^ ]
以编程方式为文本文件驱动程序设置选项 [< a href =http://msdn.microsoft.com/en-us/library/ms714864%28v=vs.85%29.aspxtarget =_ blanktitle =New Window> ^ ]
Schema.ini文件(文本文件驱动程序) ) [ ^ ]
对不起,我的错误。
没什么难的。您需要用逗号分隔字符串文本。
看看这里:
如何:拆分字符串(C#编程指南) [ ^ ]
并尝试!
另一个有用的资源:
如何:在Visual Basic中读取逗号分隔的文本文件 [ ^ ]
用C#读取和写入CSV文件 [ ^ ]
[/ EDIT]
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)[^]
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]
这篇关于如何使用c#中的csv数据加载带有字符串变量的DataTable的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文