我是编程新手,我想将 csv 文件读入表单上的文本框中。现在我正在将文件读入数据表,并认为我会将其读入 texboxes,但我不确定我是否正确。有没有更简单的方法来做到这一点?这是我到目前为止所拥有的:
protected void getftp()
{
//create Data table to temporary storage
var myTable = new DataTable();
//add columns
myTable.Columns.Add("Start_date");
myTable.Columns.Add("End_date");
//...snip...
myTable.Columns.Add("Comments");
//The 'using' command close connection when it is done
using (var reader = new StreamReader(File.OpenRead(@"C:\ftp\inbox\test.csv")))
{
while (!reader.EndOfStream)
{
//read in one line of the file
string line = reader.ReadLine();
//create an array of strings from each value in the current line
string[] values = line.Split(',');
//add the array as a row in the DataTable
myTable.Rows.Add(values);
}
}
}