Author: rcs
1. Introduction: This article describes how to create a three-layer application and will show you how to create a Web Service service. ADO.NET creates a Windows three-layer structure architecture architecture as shown below: This structure is divided into three levels: representing the layer, the business layer, the data layer. Data layer: represents the physical database. Business Layer: Responsible for data transmission between data layers and representations. Represents layer: Application client, which access the database through the business layer. Indicates that the layer is located in the local data that resides in memory, and when updating the database data, the update method provided by the business layer is implemented. This improves the performance of the application, and when updating the data is completely determined by you, improving the flexibility of programming. 2. Instance: Here we specifically make an example to see how to create a three-layer structure with VB.NET. Database: We choose SQL Server's Northwind database. Business Layer: We create a WebService as an intermediate layer. (Requires IIS Service) Representation: We write a Windows Form first step: Create webservice. The specific steps are as follows: 1. New project, select the ASP.NET Web service, named: "WebService for business layer". 2. Add two SQL DataAdapter, one for Customer_DA, point to the Customers table of the Northwind database, another as Order_DA, point to the ORDERS table of the Northwind database. 3. Then generate a Typed Dataset (Select the "Data" menu), named: super_ds. 4. Database connection has been completed, the next step we will consider communication between the representation, here we define Two methods. One is: get_dataset, it returns a sauer_ds type dataset, the other is: update_dataset, it is responsible for updating database data, the method code is as follows:
Complete code business layer follows:. Imports System.Web.Services Public Class Service1 Inherits System.Web.Services.WebService 'Web Services Designer Generated Code ......
Represents a complete code layers are as follows: Imports Data_Access_ presentation layer Public Class Form1 Inherits System.Windows.Forms.Form #Region "Windows Form Designer generated code" Public Sub New () MyBase.New () 'This call is required by the Windows Form Designer. InitializeComponent () 'Add any initialization after the InitializeComponent () call End Sub' Form overrides dispose to clean up the component list. Protected Overloads Overrides Sub Dispose (ByVal disposing As Boolean) If disposing Then If Not (components Is Nothing) Then components.Dispose () End If End If MyBase.Dispose (disposing) End Sub Friend WithEvents Button1 As System.Windows.Forms.Button Friend WithEvents Button2 As System.Windows.Forms.Button Friend WithEvents Button3 As System.Windows.Forms. Button Friend WithEvents Client_DataSet As Data_Access_ presentation layer .localhost.super_ds Friend WithEvents DataGrid1 As System.Windows.Forms.DataGrid 'Required by the Windows Form Designer Private components As System.ComponentModel.Container 'NOTE: The following procedure is required by the Windows Form Designer' It can be modified using the Windows Form Designer 'Do not modify it using the code editor
New System.Windows.Forms.DataGrid () CType (Me.Client_DataSet, System.ComponentModel.ISupportInitialize) .BeginInit () CType (Me.DataGrid1, System.ComponentModel.ISupportInitialize) .BeginInit () Me.SuspendLayout () '' Button1 'Me.button1.location = new system.drawing.point (88, 360) me.button1.name = "Button1" me.button1.tabindex = 0 me.button1.text = "loading"' Button2 'me.button2 .Location = new system.drawing.point (232, 360) me.button2.name = "button2" me.button2.tabindex = 1 me.button2.text = "update" '' Button3 'me.button3.location = new System.drawing.point (376, 360) me.button3.name = "Button3" me.button3.tabindex = 2 me.button3.text = "clear" '' client_dataset 'me.client_dataset.DataSetName = "Client_DataSet" ME. Client_dataset.locale = new system.globalization.cultureInfo ("zh-cn") me.client_dataset.namespace = "http://www.tempuri.org/customerds.xsd" 'DataGrid1' me.dataGrid1.dataMem Ber = "" me.datagrid1.location = new system.drawing.point (40, 56) me.dataGrid1.name = "DataGrid1" me.dataGrid1.size = new system.drawing.size (480, 264) Me.DataGrid1 .Tabindex = 3 'FORM1' me.autoscalebasesize = new system.drawing.size (6, 14) me.clientsize = new system.drawing.size (568, 429) Me.Controls.addrange (New System.Windows.Forms .Control () {me.dataGrid1, me.button3, me.button2, me.button1}) me.name = "form1" me.text = "form1"