Solved

N-Tier sample

Posted on 2012-12-27
1
159 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Independent Software Vendors: 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

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

737 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