I am new to programing and I would like to read a csv file into textboxes that I have on a form. Right now I am reading the file into a dataTable and was thinking I would then read it into the texboxes but I am not sure if I am going about this correct. Is there an easier way to do this? This is what I have so far:
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);
}
}
}