I'm storing data in a DataTable using SqlDataAdapter.fill. Then returning that table as JSon.
When getting that JSon in client application(Excel), it gets very slow.
Any idea how can I improve the performance.?
API code:
[Authorize]
[Route("GetRecord")]
public DataTable Records(DSModel model)
{
var table = new DataTable();
using (var da = new SqlDataAdapter(model.qstring, model.ds))
{
da.Fill(table);
return table;
}
}
Client Code:
DataTable dt = (DataTable)JsonConvert.DeserializeObject(records, (typeof(DataTable)));
foreach (DataRow dr in dt.Rows)
{
rowcount += 1;
for (int i = 1; i <= dt.Columns.Count; i++)
{
// on the first iteration we add the column headers
if (rowcount == 3)
{
osheet.Cells[2, i] = dt.Columns[i - 1].ColumnName;
}
// Filling the excel file
osheet.Cells[rowcount, i] = dr[i - 1].ToString();
}
}
For comparison, If I query the same data from Excel using SQL Connection, it takes 2-3 seconds. With the code above, its almost 11-14 seconds for a particular table.