Develop information management system with four-layer structure method

xiaoxiao2021-03-06  88

In general, the layered application constructor has some advantages: conducive to code multiplexing; convenient procedure changes; improved the robustness of code; Next, a simple acquisition user information is used as an example, explaining the construction method of the information management application of the four-layer structure: 1. Database layer / / comparison, the stored procedure with parameters is constructed than the character string in the code. SQL statement efficiency is much higher, // Therefore, it is recommended to write a common query to store procedures for calling Create Table DBo.users (FID INT NULL, FNAME NVARCHAR (50) Not Null, FPassword NVARCHAR (50) Null, Fremark NText Null )

Create Procedure DBO.SP_SEL_USER@pid int asselection * from users where fid = @ PID

2. Data component layer / / Returns the application object of a certain format according to the database object information such as the SQL statement provided by the caller. // Data components require a relatively small number, but the use surface is wide, and more comprehensive transactions and abnormalities are generally needed, and this is limited to the space is omitted. public class CDatabase {private string mConnectString = "Provider = SQLOLEDB.1; Data Source = mymachine; Initial Catalog = mydatabase; User ID = sa; Password = pwd;"; public bool RunProcedure (string sProcedureName, System.Data.OleDb.OleDbParameter [] oParams, out OleDbDataReader oReader) {OleDbConnection oConnection = new OleDbConnection (this.mConnectString); OleDbCommand oCommand = new OleDbCommand (sProcedureName, oConnection); oCommand.CommandType = CommandType.StoredProcedure;

转载请注明原文地址:https://www.9cbs.com/read-98317.html

New Post(0)