如何使用.text文件作为数据表? [英] How to use a .text file as data table?
本文介绍了如何使用.text文件作为数据表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想使用c#Windows应用程序将文本文件作为数据表访问.
我尝试过的事情:
i want to access a text file as data table by using c# windows application.
What I have tried:
private void button2_Click(object sender, EventArgs e)
{
string line;
StreamReader file = new System.IO.StreamReader(@"C:\Users\Touhid Hasan\Desktop\audio\pro.txt");
while ((line = file.ReadLine()) != null)
{
if (line.Contains(textBox2.Text))
{
pro = file.ReadLine();
break;
//string tou = file.ReadLine();
}
pro = file.ReadLine();//search reult to pro
}
file.Close();
label1.Text = pro;
// player.URL = (path + word + ".wav");
// player.controls.play();
}
}
推荐答案
在此处查看答案,大多数与使用CSV文件有关: ^ ]
像这样的东西:
See the answers here, most are about using a CSV file: c# - Populating a dataset from a CSV file - Stack Overflow[^]
Something like this:
DataTable dtDataSource = new DataTable();
string[] fileContent = File.ReadAllLines(@"..\\Book1.csv");
//Create data table columns dynamically
string[] columns = fileContent[0].Split('','');
for (int i = 0; i < columns.Count(); i++)
{
dtDataSource.Columns.Add(columns[i]);
}
string[] rowData = fileContent[i].Split('','');
dtDataSource.Rows.Add(rowData);
if (dtDataSource != null)
{
dataGrid1.ItemsSource = dtDataSource.DefaultView;
}
这篇关于如何使用.text文件作为数据表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文