Solved

N-Tier sample

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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

744 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now