I have question, that maybe someone here wouldn\'t mind to help me with. I have lets say 3 datatables, each one of them has the following columns:
size, quantity, amo
The first answer is correct, but if you have a large amount of data (in my project I had 8.000 rows * 8 columns) is tragically slow.... Having a string that becomes that large in c# is why that solution is forbiden
Instead using a large string I used a string array that I join at the end in order to return the string of the html table. Moreover, I used a linq expression ((from o in row.ItemArray select o.ToString()).ToArray()) in order to join each DataRow of the table, instead of looping again, in order to save as much time as possible.
This is my sample code:
private string MakeHtmlTable(DataTable data)
{
string[] table = new string[data.Rows.Count] ;
long counter = 1;
foreach (DataRow row in data.Rows)
{
table[counter-1] = "" + String.Join(" ", (from o in row.ItemArray select o.ToString()).ToArray()) + " ";
counter+=1;
}
return "" + String.Join("", table) + "
";
}