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 = "";

sb.Append("<table>");
do
{
   sValue1 = rs.getvalue(Col1);
   sValue2= rs.getvalue(Col2);
   sValue3 = rs.getvalue(Col3);
   
   sb.Append("<tr>");
   sb.Append("<td>"+sValue1+"</td>");
   sb.Append("<td>"+sValue2+"</td>");
   sb.Append("<td>"+sValue3+"</td>");
   sb.Append("</tr>");
} (while rs.getNextRecord());

sb.Append("</table>");

Response.Write(sb.ToString());
Response.End();

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 ...
Pete2003Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ferguslogicCommented:
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
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
kolluCommented:
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.
0
Pete2003Author Commented:
how else would you display a table without the table tags ??
0
AgariciCommented:
instead of  sb.Append("<td>"+sValue1+"</td>");
do
 sb.Append("<td>");
 sb.Append(sValue1);
 sb.Append("</td>");


hth,
A.
0
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
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.