473,804 Members | 3,250 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(sqlstri ngTable)

while(read)
{
output category name

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

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

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

use nested for loops to output <list>categor y 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 1128
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_nam e, ct.category_id, it.item_name,
it.item_id, it.quantityonha nd from category ct inner join item it on
ct.category_id = it.category_id where it.quantityonha nd > 0 order by
ct.category_nam e 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*******@yaho o.com> wrote in message
news:uk******** *****@TK2MSFTNG P14.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(sqlstri ngTable)

while(read)
{
output category name

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

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

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

use nested for loops to output <list>categor y 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*******@hotm ail.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_nam e, ct.category_id, it.item_name,
it.item_id, it.quantityonha nd from category ct inner join item it on
ct.category_id = it.category_id where it.quantityonha nd > 0 order by
ct.category_nam e 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*******@yaho o.com> wrote in message
news:uk******** *****@TK2MSFTNG P14.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(sqlstri ngTable)

while(read)
{
output category name

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

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

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

use nested for loops to output <list>categor y 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
11103
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 the HTML form to the web server? Since most of the time I heard this term in ASP.NET circle, thats why I raise this question. Please advise. Thanks!
6
2253
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 increment operation. Correct me if I'm wrong, Let's see trival example:
4
2632
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 (as this is part of the PUBLIC group privilege - if I am not wrong). From a practical stand point, what is the application of such concept. 2. Suprisingly, if the schema is an implicitly created, everyone else can create objects in it too. What...
2
4858
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 signature. A class inherits publicly from this base class and redefines one of the two functions in the derived class. In that case, a derived class object cannot access the other base class function that it hasn't redefined. I'm posting a code snippet...
2
2726
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 anybody know of either a module in python that supports making concept maps or a program that stores its concept maps in an easily duplicable xml format? Any code that anybody has written in python that is relevant in the slightest to creating a concept...
0
9708
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9588
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10589
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10340
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10327
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10085
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7625
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6857
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
3
2999
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.