I tested the three-tier structure system in Asp.net.

Source: Internet
Author: User
Display Layer/logic layer/data layer
The display layer is usually composed of. aspx/. aspx. CS files. It is used to display data pages. If the data pages are divided by three layers, the page layer should directly call the methods in the logic layer.
The logic layer is an intermediate layer used to connect the page layer and data layer. It provides interfaces to the page layer and also calls methods from the data layer for the page layer to use.
The data layer is the bottom layer, which is generally used for data operations.
Oh, now let's explain this three-tier system. Let's take a test.

Page Layer[Default. aspx]: Only one DataGrid Control and one label control.
Final execution result of the page

Default. aspx. CS File

Using system; using system. collections; using system. componentmodel; using system. data; using system. drawing; using system. web; using system. web. sessionstate; using system. web. ui; using system. web. UI. webcontrols; using system. web. UI. htmlcontrols; using lemongtree. BL; Summary of namespace services {// <summary> // _ default. /// </Summary> public class _ default: system. web. UI. page {protected system. web. UI. webcontrols. label label1; protected system. web. UI. webcontrols. dataGrid datagrid1; private void page_load (Object sender, system. eventargs e) {// place the user here Code To initialize the page if (! Page. ispostback) {setup ("select * from favor", datagrid1) ;}} private void setup (string SQL, DataGrid DG) {Blyer BL = new Blyer ("Server = lemongtree; uid = sa; Pwd = sa; database = BBS "); BL. showdatagrid (SQL, DG); label1.text = bl. error;} # region web form designer generated code override protected void oninit (eventargs e) {// codegen: The call is ASP.. NET web form designer. // Initializecomponent (); base. oninit (e) ;}/// <summary> /// the designer supports the required methods-do not use the code editor to modify the content of this method. /// </Summary> private void initializecomponent () {This. datagrid1.pageindexchanged + = new system. web. UI. webcontrols. datagridpagechangedeventhandler (this. datagrid1_pageindexchanged); this. load + = new system. eventhandler (this. page_load) ;}# endregionprivate void datagrid#pageindexchanged (Object source, system. web. UI. webcontrols. datagridpagechangedeventargs e ){}}}

Logic layer[BL. CS]

Using system; using system. text; using system. data; using system. data. sqlclient; using lemongtree. DB; using system. web. UI. webcontrols; namespace lemongtree. BL {/// <summary> /// Summary of BL. /// </Summary> public class Blyer {private string strconn; private sqlconnection objconn; private dbmaster dBm; private string errmsg; Public Blyer (string strconn) {// todo: add the constructor logic here // This. strconn = strconn; this. objconn = new sqlconnection (strconn); dBm = new dbmaster (strconn);} public string error {get {return errmsg;} public void showdatagrid (string strsql, DataGrid dgrd) {dgrd. datasource = dBm. dataset (strsql); errmsg = dBm. error; dgrd. databind ();}}}

Data Layer[DB. CS]

 using system; using system. text; using system. data; using system. data. sqlclient; using Microsoft. applicationblocks. data; namespace lemongtree. DB {///  /// Summary of the DB. ///  public class dbmaster {private string strconn; private string MSG; private sqlconnection objconn; Public dbmaster (string strconn) {// todo: add the constructor logic here // This. strconn = strconn; this. objconn = new sqlconnection (strconn);} public string error {get {return MSG;} public dataset (string strsql) {dataset DST = new dataset (); try {DST = sqlhelper. executedataset (strconn, commandtype. text, strsql); MSG = "Total number of records: " + DST. tables [0]. rows. count. tostring () + ""; return DST;} catch (sqlexception e) {MSG = E. message;} finally {DST. dispose () ;}return null ;}}
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.