473,400 Members | 2,145 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,400 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 1115
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...
1
by: googleo | last post by:
Hi, in my application I want to handle and store data in a hierarchic data structure. For example: persons who manage houses; houses have various numbers of floors; floors have various numbers...
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: JC Mugs | last post by:
I am having a conceptual problem. When working with a forms & Code sections which is correct method and how do they differ when working with fields? Code Private Sub CExt1_BeforeUpdate(Cancel...
4
by: jm | last post by:
Consider: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon/html/vbconwhenshouldiimplementinterfacesinmycomponent.asp // Code for the IAccount interface module. public...
5
by: strutsng | last post by:
I want to clarify the concept of submitting the form to the web server. PHP is just an example here, it applies to any web programming languages. On page1.php, <form name="myform"...
20
by: Stan Sainte-Rose | last post by:
Hi, Sorry about this newbie question, but I have some questions about the MDI Concept. I have a MdiParent form that calls a Child Form (A). This Child Form (A) could call another Form (B). ...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.