Solved

N-Tier sample

Posted on 2012-12-27
1
156 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 500 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

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

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

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

777 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