Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 175
  • Last Modified:

Generating a table on the fly from a DB

Hi All,

I have a table with some records and I want to generate a HTML tbale to display them ... this is what I have done ...

opend database
execute SQL statement
get back recordset

StringBuilder sb = new StringBuilder()
string sValue1 = "";
string sValue2 = "";
string sValue3 = "";

   sValue1 = rs.getvalue(Col1);
   sValue2= rs.getvalue(Col2);
   sValue3 = rs.getvalue(Col3);
} (while rs.getNextRecord());



If I have 5000 records the DB call goes quick but the text generation takes ages ...

Is there a way to speed this up ?

I DO NOT want to use a datagrid, I want to generate my own ...
1 Solution
You will find that the speed issue is not being caused by the HTML rendering but by the actual string concatenation that you are doing.

It is the x = x+ y that is causing the speed issue.

You can verify this by using a simple response.write for each  row and column instead of performing the concatenation.

So instead of concatenating the whole table together and then writing it one time, if it is possible for you to use response.write for each row and TD then you will see an enormous speed increase here.

If this is not possible, then you could always return the data as xml and apply an XSLT stylesheet to it which will be a lightning fast way to solve the issue.

Either way you go, get rid of the concatenation and you will no longer have the problem.

:) thanks
I also got the same problem for exporting data to excel.If you dont have the <table><tr><td> format things it will be faster with the string builder to display data.Please do let me know if you find with the table tags.
Pete2003Author Commented:
how else would you display a table without the table tags ??
instead of  sb.Append("<td>"+sValue1+"</td>");

Pete2003Author Commented:
ok sorry that was a creative type on my part up top ... but even if everything is included in Appends and there is no +
I need to know if there is a way of making it fatser ... but I really like ferguslogic's idea of the multiple writes

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now