Ado|server|sqlserver| Program | advanced | architecture
NET Advanced Development One: Use Vb.net+ado.net+sql server to develop three-tier architecture application procedures
One: What is a three-tier architecture:
Three-tier architecture, as the name suggests, we will use the program from the whole into three separate and interrelated level, the three layers are: User layer, business logic layer, data layer
。 User layer is the application of the program and user interface, such as: Web page. In the user layer, commonly used technology such as: HTML, CSS, JavaScript, asp/asp.net and so on. Business Logic Layer
is to encapsulate some of the logic and rules of business processing, which provides interfaces to interact with the user layer and the data tier. At the logical level, today's more popular technologies and specifications, such as:
Microsoft's Com/dcom/com+/net components, SUN's EJB, and so on. Data layer is mainly to provide the business logic layer of data interface and background data management, more typical database management department
The EC has: SQL sercer 2000/2005, Orcale 8i/9i,db2 and so on. The benefit of a three-tier architecture is to divide the application into separate layers, and when a layer needs to change,
Will not have a large impact on other levels, facilitate the maintenance of the application process. At the same time, the structure between layer and layer is clear and easy for us to develop and deploy.
Two: The idea of developing three-tier architecture with NET:
NET platform easy to operate, powerful functions, conducive to our short time to develop a larger scale, more complex application procedures. Below, we use a simple example (read the data in the database
To see how to develop a standard application based on a three-tier architecture.
Step one: We use SQL Server as the background database management system in the background. So we first open SQL Server Enterprise Manager, build our own database, we just Jane
Single name for Stu, at the same time, need to establish a table (student), the table has three fields, respectively, ID (student number), name (name), Class (Class). At the same time, we first fill in some
Data into the student table, to facilitate the completion of the program design of the LIFO test.
At the same time, we need to set up a stored procedure in the Query Analyzer, please do not care why to use stored procedures, but the logic layer in the interaction with the database need. (
Interested can view the benefits of using stored procedures, where we do not do more introduction)
The stored procedure is as follows:
CREATE proc P_select
As
SELECT * FROM Student
Go
Step Two: We start vsnet application program, select New Project, select Class Library, set up a class library called Mylib, the purpose of building class library is to encapsulate the logic of the business layer. In the class
Library, the default namespace is Mylib, where you are prompted for namespaces because we use them when instantiating a class at a later user level. Then we'll see in the solution that there's a tacit
Recognized as a class called Class.vb. In the code editing area, we change the class to MyClass. (In fact, you can not change, modification is only convenient for us in the reference time, convenient for us to identify). And then
We write the code for the class, in the class, we need to define some variables and methods and attributes, events, and so on. In this class, we just define one of the following:
Tip: Import namespaces first: Imports System.Data.SqlClient
Code for the class:
Public Class MyData
Public Conn as New SqlConnection ("Data source= (local); user id=sa;password= ';d atabase=xiaoxiao")
Function myDataSet () as DataSet
Dim command as New SqlCommand ()
Try
Dim Myada as New SqlDataAdapter ()
Dim myds as New DataSet ()
Conn. Open ()
Command. Connection = conn
Command.commandtype = CommandType.StoredProcedure
Command.commandtext = "P_select" load is a stored procedure that displays data
Myada. SelectCommand = command
Myada. Fill (myDS, "1")
Return myds
Conn. Close ()
Catch
MsgBox ("Failed")
End Try
End Function
End Class
Then we need to compile the newly created class to build the DLL's file so that we can reference it using him. Click Mylib Right Button--"build, you can."
Step three: Click on the file-"new-" Project-"Windows project, we build a Windows application program, named MyForm1 in the interface with a button and a DataGrid
Control.
In order to be able to use the class we just created, we need to add a reference and refer Mylib to our MyForm1. Then we write the code under the button:
Import namespaces First: Imports Mylib
The code under the button:
Private Sub button1_click (ByVal sender as System.Object, ByVal e as System.EventArgs) Handles Button1.Click
Dim myDS as New MyClass ()
DataGrid1.DataSource = Myds.mydataset
End Sub
You can then start the program to display data from the student table in the database Stu.
Third: The experiment:
Please follow the above tips, your own computer operation exercises, will be more profound understanding of the development of the program.
Four: Conclusion
We first built a standard three-tier architecture program with an example of displaying database information. The main intention is to be a reference for readers who want to do advanced development on the net platform. Of course, the actual effect of this example may not be big, just let us understand how to develop a three-tier structure system of the general idea, if you want to design a more powerful program may be more complex. There is no drawing in the article, it may look boring, but the text of the explanation seems to be relatively simple. Hope to give some readers some inspiration.
Solemnly declare: This article is purely individual original, the purpose in with and each netizen carries on the study development the exchange, please do not arbitrarily copy and revise. If you want to quote, please specify the source. Thank you!