[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

N-Tier sample

Posted on 2012-12-27
1
Medium Priority
?
164 Views
Last Modified: 2013-01-10
What would DAL and BAL looks like if there a subroutine that retreives data from sql, using sqldatareader, and display on textboxes and lables?

using sqlconnect as new sqlconnection("mycon string")
using sqlcomnd as new sqlcommand("mysp", sqconnect)
sqlcomnd.commandtype = commandtype.storeprocedure
sqlcomnd .parameters.addwithvalue("@id", ????)
dim dr as sqldatareader = sqlcomnd.exedutereader
dr.read

txtfirstname.text = dr.item("firstname")

etc...

end using
end using


http://www.mindstick.com/Articles/d36ceb0f-018c-4979-b2f5-a4a1e616cb5b/?N-Tier%20Architecture%20in%20ASP.NET
0
Comment
Question by:VBdotnet2005
1 Comment
 
LVL 16

Accepted Solution

by:
Stephan earned 2000 total points
ID: 38726545
What I mostly do is the following:

- Create a library for the DataLayer
- Create a library for the BusinessLayer
- Create a project for the PresentationLayer

If you want to use the SqlCommand etc.. You put this in the datalayer. From the busineslayer you connect to the datalayer and ask for information (or save whatsoever).

The data you receive like a single datareader, I use this as parameter:
public T SomeMethod<T>(Func<IDataRecord, T> add) where T : class

And inside the call for loading, returning the data:
T record = default(T);
            using (SqlDataReader reader = cmd.ExecuteReader())
            {
                if (reader.Read())
                {
                    record = add(reader);
                }
            }

In this way you can use an delegate to tell the datalayer how you want to receive your data. For suggestion a Model. You create models in your domain (you can put it in the BusinessLayer). And you can fill them from the datalayer end.
Just when you call the SomeMethod(), you can do the following:

Person perso = DataLayer.SomeMethod(x => new Person(x));

Inside the model you create a constructor which accepts IDataRecord, from there you can get the data you need.

In this way you can fill your model and keep that separation of concern.

Now you can pass it on to the presentation layer.
I think from there it makes sense.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses

826 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question