473,320 Members | 1,865 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

asp.net c# concept question

I need to write a web page that outputs a table from database. ( i want to
write my own code, don't want to use the built-in control)
I came up with two ways of doing this (i use c# 2.0)
1.
pesudo code

sqlstringTable = "select category_name from table1"
execute(sqlstringTable)

while(read)
{
output category name

sqlstringTable = "select * from table2"
execute(sqlstringTable2)
while(read)
{
output values of all cell in this row
}
}
2.
sqlstringTable = "select category_name from table1"
execute(sqlstringTable)

while(read)
{
store information to <list>category
}

for (i=0 i<=size of <list>category; i++
{
sqlstringTable = "select * from table2"
execute(sqlstringTable2)
while(read)
{
store to <list>row
}
}

use nested for loops to output <list>category with corresponding <list>row

Method 1 is how i would normally write this. but since im getting into c#
2.0 i want to try out this new feature. did i understand this correctly?
Also any memory used to store <list> will be released after the page is
loaded correct?

Howard
Mar 16 '06 #1
2 1107
Hello Howard,

Your two methods both involve issuing two queries to the database and
joining the data in your app. That doesn't make any sense at all.
Simply issue a SQL statement that joins the 'category' rows and 'table2'
rows into a single resultset, and then fill your table from that data.
SQL is going to be considerably easier to write the code and considerably
easier to manage the results than either of the two methods you describe.

I don't know what database you have under the covers or what database schema
you have. Assuming your category table has a category name and category id,
and the item table has a category id in it to form the relationship, the
join would look something like this. I added a 'where' clause to show you
where one would go, but your examples did not have one, so feel free to drop
it if this is not needed.

string sSql = "Select ct.category_name, ct.category_id, it.item_name,
it.item_id, it.quantityonhand from category ct inner join item it on
ct.category_id = it.category_id where it.quantityonhand > 0 order by
ct.category_name desc";

(caveat: air code at 11:30pm... check the syntax in the SQL environment of
your choice before coding this into your app)
--
--- Nick Malik [Microsoft]
MCSD, CFPS, Certified Scrummaster
http://blogs.msdn.com/nickmalik

Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
I do not answer questions on behalf of my employer. I'm just a
programmer helping programmers.
--

"Howard" <ho*******@yahoo.com> wrote in message
news:uk*************@TK2MSFTNGP14.phx.gbl...
I need to write a web page that outputs a table from database. ( i want to
write my own code, don't want to use the built-in control)
I came up with two ways of doing this (i use c# 2.0)
1.
pesudo code

sqlstringTable = "select category_name from table1"
execute(sqlstringTable)

while(read)
{
output category name

sqlstringTable = "select * from table2"
execute(sqlstringTable2)
while(read)
{
output values of all cell in this row
}
}
2.
sqlstringTable = "select category_name from table1"
execute(sqlstringTable)

while(read)
{
store information to <list>category
}

for (i=0 i<=size of <list>category; i++
{
sqlstringTable = "select * from table2"
execute(sqlstringTable2)
while(read)
{
store to <list>row
}
}

use nested for loops to output <list>category with corresponding <list>row

Method 1 is how i would normally write this. but since im getting into c#
2.0 i want to try out this new feature. did i understand this correctly?
Also any memory used to store <list> will be released after the page is
loaded correct?

Howard


--
--- Nick Malik [Microsoft]
MCSD, CFPS, Certified Scrummaster
http://blogs.msdn.com/nickmalik

Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
I do not answer questions on behalf of my employer. I'm just a
programmer helping programmers.
--
Mar 16 '06 #2
In addition to the ability to do this in a single query, I have concerns
with both approaches as well. With respect to the 2nd approach, using a
generic or some type of collection, there's only a benefit to be had if you
need to manipulate or re-iterate the data during that function. From your
example that doesn't seem to be the case. In your example there's no benefit
to throwing it into a generic as the work is simply thrown away a few
microseconds later. Now if you decide to cache the data, then you're on to
something!

There's also no reason to avoid the pre-built controls. As is, whatever
method you chose to output your data is going to be considerably less
maintanable and clean than using something like a Repeater. A bunch of
Response.Write's, server-side object creation or string concatenation is not
the right way.

Karl
--
http://www.openmymind.net/

"Nick Malik [Microsoft]" <ni*******@hotmail.nospam.com> wrote in message
news:LN******************************@comcast.com. ..
Hello Howard,

Your two methods both involve issuing two queries to the database and
joining the data in your app. That doesn't make any sense at all.
Simply issue a SQL statement that joins the 'category' rows and 'table2'
rows into a single resultset, and then fill your table from that data.
SQL is going to be considerably easier to write the code and considerably
easier to manage the results than either of the two methods you describe.

I don't know what database you have under the covers or what database
schema you have. Assuming your category table has a category name and
category id, and the item table has a category id in it to form the
relationship, the join would look something like this. I added a 'where'
clause to show you where one would go, but your examples did not have one,
so feel free to drop it if this is not needed.

string sSql = "Select ct.category_name, ct.category_id, it.item_name,
it.item_id, it.quantityonhand from category ct inner join item it on
ct.category_id = it.category_id where it.quantityonhand > 0 order by
ct.category_name desc";

(caveat: air code at 11:30pm... check the syntax in the SQL environment of
your choice before coding this into your app)
--
--- Nick Malik [Microsoft]
MCSD, CFPS, Certified Scrummaster
http://blogs.msdn.com/nickmalik

Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
I do not answer questions on behalf of my employer. I'm just a
programmer helping programmers.
--

"Howard" <ho*******@yahoo.com> wrote in message
news:uk*************@TK2MSFTNGP14.phx.gbl...
I need to write a web page that outputs a table from database. ( i want to
write my own code, don't want to use the built-in control)
I came up with two ways of doing this (i use c# 2.0)
1.
pesudo code

sqlstringTable = "select category_name from table1"
execute(sqlstringTable)

while(read)
{
output category name

sqlstringTable = "select * from table2"
execute(sqlstringTable2)
while(read)
{
output values of all cell in this row
}
}
2.
sqlstringTable = "select category_name from table1"
execute(sqlstringTable)

while(read)
{
store information to <list>category
}

for (i=0 i<=size of <list>category; i++
{
sqlstringTable = "select * from table2"
execute(sqlstringTable2)
while(read)
{
store to <list>row
}
}

use nested for loops to output <list>category with corresponding
<list>row

Method 1 is how i would normally write this. but since im getting into c#
2.0 i want to try out this new feature. did i understand this correctly?
Also any memory used to store <list> will be released after the page is
loaded correct?

Howard


--
--- Nick Malik [Microsoft]
MCSD, CFPS, Certified Scrummaster
http://blogs.msdn.com/nickmalik

Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
I do not answer questions on behalf of my employer. I'm just a
programmer helping programmers.
--

Mar 16 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Matthew Louden | last post by:
I want to know if the PostBack concept applies to HTML web-based forms, regardless of what programming technologies we use: For example, ASP, ASP.NET, Java, CGI, etc... PostBack means to send...
6
by: Sergey | last post by:
Hello! Could anybody be kind enough to explain this concept? Why C++ make two ops for prefix and postfix ++ operator? As I guess, it is possible to implement both cases via sole prefix...
4
by: cmc | last post by:
I need some clarification to help me understand the DB2 strucure more. The questions are about "implicit schema" 1. This is a very interest concpet that DB2 let every user to create new schema...
2
by: developer.new | last post by:
Hi I have a question regarding this concept I learned about recently: Name Hiding. Here's what I've come across: There is a base class with two functions with the same name but different...
2
Subsciber123
by: Subsciber123 | last post by:
I am writing a program to create family trees. It is stable, but I would say that it is still in the pre-alpha stage. Anyway, I would like to be able to export the tree to a concept map. Does...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.