Visual Studio with 2019 and C#
I have a flat file with data in this format:
CustomerName<tab>CustomerAddress<tab>CustomerEmail<tab>CustomerPhone etc....
Tom<tab>123 Chestnut Street, NY, NY 10001<tab>Tom@gmail.com<tab>212-555-1212
Dick<tab>234 Oak Street, LA, CA 91210<tab>Dick@gmail.com<tab>747-555-1212
Harry<tab>789 Maple Drive, Reno, NV 89508<tab>Harry@yahoo.com<tab>775-555-1212
etc...
The columns can vary from about 5 to 15 columns, depending on the customer file given to us.
Our users want to be able to preview a sample of the data, anywhere from 1 to 50 sample rows of data. However they insist on seeing the data pivoted on the page:
Column1 Column2 Column3 etc...
Tom Dick Harry
123 Chestnut Street... 234 Oak Street... 789 Maple Drive...
Tom@gmail.com Dick@gmail.com Harry@yahoo.com
212-555-1212 747-555-1212 775-555-1212
etc...
I have this special customer class for this purpose:
public class Customer {
public string Column1 { get; set; }
public string Column2 { get; set; }
public string Column3 { get; set; }
//etc.... to 50 columns
}
But I am having difficulty coming up with an elegant way to code this. If I can get the data into a System.Data.DataTable in that pivoted form, I can easily get it to an html table. Any thoughts on how to cycle through the rows of data to get it into the class? Not sure what are the best intermediate classes to use. I don't want to hard code something like this:
...
for (int i = 0; i < columnCount; i++) {
Customer c = new Customer();
c.Column1 = row1[i].ToString();
c.Column2 = row2[i].ToString();
c.Column3 = row3[i].ToString();
//etc...
}