Click here to Skip to main content
15,893,487 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more: (untagged)
Hello, I'm relatively new to c# and even newer to asp.net and ado.net.
I'm trying to improve my skills in the asp.net and ado.net areas.

I'm working on an a sample app where I want to display items in a web page based on what the user has selected from a drop-down list.

A couple of questions I have while on this learning path:

1 -Are all database queries and "presentation" done within the .aspx files, or are some done in the .cs files?

Thanks in advance.
---------
Jeff
Posted

Good question. In fact, your database queries SHOULD come from a seperate dll which encapsulates DB code. Microsoft have added ways to do database stuff in the ASPX, but no-one uses them except hobbyists and people who don't know/don't care about writing good code. You should run from any control that has you typing SQL into your aspx. You should try to wrap your database code into a seperate layer. Ideally, your database layer would not return database objects but take and return lists of classes in your project.

 
Share this answer
 
Jeff,
I like to break my design into three layers

1. Presentation
2. Business Logic
3. Database

1. In presentation layer I put only those that are of UI related. This will go directly into the aspx pages, user controls (usually I create on separate dll) and any UI related logic

2. Database. This is strictly database related classes. NO other code belongs here.

3. In business logic goes any middle-ware code that does not belong to any of the two categories.

Now, notice how I said 'This goes to separate dll' in the first case. I don't go crazy in creating many dlls. The rule of thumb I use is, if the code can be reused somewhere else, then I create it in its logical dll, so I can easily take it to another project and reused. That means the other layers may have multiple dlls as well.

Again, there are projects I have worked which they have only 2 layer or more than 3 layers. It does not have to be only 3 layers. The scope of the project will decide how you want to break your logical designs. In some cases you may be able to get away with single layer.

 
Share this answer
 


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900