I have a function in C# like below:
public static string ConvertDataTableToHTMLExtra(DataTable dt)
{
string html = "";
html += "<table>";
//add header row
html += "<thead>";
html += "<tr>";
for (int i = 0; i < dt.Columns.Count; i++)
html += "<td>" + dt.Columns[i].ColumnName + "</td>";
html += "</tr>";
html += "</thead>";
//add rows
for (int i = 0; i < dt.Rows.Count; i++)
{
html += "<tr>";
for (int j = 0; j < dt.Columns.Count; j++)
html += "<td>" + dt.Rows[i][j].ToString() + "</td>";
html += "</tr>";
}
html += "</table>";
return html;
}
The datatable is filled by using a Stored Procedure. After the content is set to dt, this function above is called. It is working a little slow but without error, as long as we have less than ~6000 rows. Above ~6000, it is returning timeout error. Execution time of SP is less than 2 seconds still.
Is there any better way to re-develop such a function? Any help or advice would be appreciated.