从.txt文件填充数据表或数据集 [英] populate Datatable or dataset from .txt file
本文介绍了从.txt文件填充数据表或数据集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
要从.txt文件中获取数据或将数据从其中读取到C#.net中的数据表中的代码?
code to get or read data from .txt file into datatable in C# .net?
推荐答案
在此不提供代码.你试过什么了? Google提供了大量有关此主题的示例和文章.
无论如何,我首先会开始阅读有关 ADO.Net [ ^ ]和数据集 [从带分隔符的文本文件中填充数据集 [ ^ ]
http://www.dotnetspider.com/resources/30594-Import-Flat- Files-into-DataSet.aspx [ ^ ]
We don''t give code here. What have you tried so far? Google has tons of examples and article about this topic.
Anyway, I would first start reading about ADO.Net [^]and DataSet [^]to understand the basics.
Here are some articles which can give you a headstart:
Fill a DataSet from delimited text files[^]
http://www.dotnetspider.com/resources/30594-Import-Flat-Files-into-DataSet.aspx[^]
检查此示例
Hi ,
Check this Example
private void button2_Click(object sender, EventArgs e)
{
DataTable dt = new DataTable();
DataColumn col = new DataColumn("test");
col.DataType = System.Type.GetType("System.String");
dt.Columns.Add(col);
string[] aa = File.ReadAllLines("C:\\log.txt");
foreach (var item in aa)
{
DataRow dr = dt.NewRow();
dr[0] = item.ToString();
dt.Rows.Add(dr);
}
dataGridView1.DataSource = dt;
}
最好的问候
米特瓦里(M.Mitwalli)
Best Regards
M.Mitwalli
这篇关于从.txt文件填充数据表或数据集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文