ASP. NET development, from Layer 2 to Layer 3 to object-oriented (5), asp.net object-oriented
This is the last article of a series of blog posts. It is also intended for beginners. I hope you can have a better understanding of ASP. NET programming.
ASP. NET development, from the second layer to the third layer, to the object-oriented (4) "http://www.cnblogs.com/insus/p/3837898.html, Insus. NET allows you to understand that you do not need to write SQL statements, but just pass in fields, values, or conditions. Although some examples are listed in this article, they can be used and expanded.
Insus. NET in the third article ASP. NET development, from Layer 2 to Layer 3, To object-oriented (3) http://www.cnblogs.com/insus/p/3826706.html, also combines SQL Server parameters with Stored Procedure class BizBaseSQLSp. cs.
This is an example of how to use this class. From the very beginning. Create a table in the database and add, edit, update, or delete the table.
To demonstrate all public methods or functions of this class as much as possible, Insus. NET should give a detailed introduction and description as much as possible.
First, develop the database, create a table [dbo]. [Employee], and design three fields. The primary key field is [Work_nbr], the data type is NVARCHAR, and the storage character is used.
Create a stored procedure for adding data [dbo]. [usp_Employee_Insert]:
Input three parameters. In the subject code, you must first determine whether the primary key exists. If not, add the record.
A stored procedure [dbo]. [usp_Employee_Getall] is used to obtain all records of the table:
Create a deleted stored procedure [dbo]. [usp_Employee_Delete]. Delete the record:
Create a stored procedure [dbo]. [usp_Employee_GetNameByNumber] for obtaining the value of a field in a record with conditions to pass in the primary key to obtain the Scalar value.
The following stored procedure [dbo]. [usp_Employee_IsExisting] is used to determine whether a certain record of a condition has been stored in the table:
The last stored procedure is the updated stored procedure [dbo]. [usp_Employee_Update]
The database has been designed, and the last written ASP. NET development, from Layer 2 to Layer 3 to object-oriented (3), the parameter and stored procedure class BizBaseSQLSp. cs of the processing Server. We can use this logic to create an object. This object name is generally named as a data table name. In the database, each table can implement an object.
Hierarchical development: Some people design and develop databases, and some people develop various objects in the logic layer. The following is a front-end webpage. Create An aspx webpage. Add records on the webpage:
Implement the ButtonAdd_Click event in. aspx. cs:
Next, the data of the Data Table is displayed, that is, the records added by the user are displayed, and a GridView control is displayed on the webpage:
Bind the GridView control in the background:
To continue writing, we need to implement the delete record function. That is to say, in the GridView control, click Delete to delete the record clicked by the GridView. In the GridView control, add the highlighted html markup section below:
Now, we can delete the program in. aspx. cs:
Check whether there are exceptions or errors in the implementation:
To apply other BizBaseSQLSp methods or functions, add a text box and enter the employee ID to get the employee name of this employee ID pair:
The following is the ButtonGet_Click event program to obtain the Scalar value:
Whether it is front-end javascript or background development, it is a function, an event, and corresponding implementation. Differentiate objects and ideas.
Another function is to use SqlDataReader to determine whether a record has been saved. In fact, when adding a record, Insus. NET writes to the stored procedure, you can step by step, first determine whether there is storage, if there is, return.
This is just html markup. You need to write the button#click event to make this function vivid:
Let's take a look at the real-time demonstration of this function:
Write it here. For editing and updating, Insus. NET has already written a stored program and used it as your hands-on capability.
Asp net development layer-3 Architecture
Why is a three-tier architecture used?
Because each layer can be put on different physical servers after only a small amount of code is changed, the structure is flexible and the performance is better. In addition, other layers in each layer are completely invisible. Therefore, you no longer need to re-compile or change all layers to modify or update a layer. This is a very powerful function. For example, if you separate the data access code from the business logic layer, after the database server changes, you only need to change the data access code because the business logic layer remains unchanged, therefore, you do not need to change or recompile the business logic layer.
A layer-3 Application usually includes the presentation layer, business layer, and data layer. Next let's take a look at what each layer does.
Presentation Layer)
The presentation layer is used to display user interfaces and to "Drive" These interfaces using classes and objects in the business layer.
In ASP. NET, this layer includes aspx pages, user control, server control, and some security-related classes and objects.
Business Tier)
The business layer is used to access the data layer, fetch, modify, and delete data from the data layer, and return the results to the presentation layer.
In ASP. NET. This layer includes using SqlClient or OleDb to retrieve, update, and delete data from SQL Server or Access database, and placing the obtained data in DataReader or DataSet and returning it to the presentation layer. The returned data may only have one integer number, for example, the number of row records in a table. However, the data must be calculated at the data layer.
Data Tier)
The data layer is a database or data source. In. NET, it is usually an SQL Server or Access database, but not limited to these two forms. It may also be Oracle, mySQL, or XML.
What is the impact of object-oriented on the three-tier architecture?
The three layers are called client (browser)-Web server-database server.
What you call the Layer 3 is ASP. NET development, which puts data access in a middle layer. The most obvious is the use of ObjectDataSource.
First, do not stick to the so-called three-tier architecture. If you do not need complex data processing that often changes to the data source, it doesn't matter if you use a few layers.
Second, we need to understand the application scenarios of layer-3 or multi-layer architecture. Sometimes our data sources may come from different database servers, or even the merger of data tables and other objects. Data Update may require custom rules to avoid conflicts, or we have foreseen that the data source may change frequently. In this case, the data processing layer is more flexible.
Finally, for ASP. NET, check the ObjectDataSource example on MSDN to understand the basic layer-3 Application Method and deepen the understanding of the layer-3 application.
Reference: www.alixixi.com/..iegou/