Three-tier development of entity classes and data access classes

Source: Internet
Author: User

entity classes, data access classes

Entity classes: Encapsulation

Encapsulates a class with a class name consistent with the database table name, the member variable name is consistent with the column, and one more underscore.

Members make the properties of the encapsulation play consistent with the column names in the datasheet.

Each row of data can be stored as an object, manipulating this object, is equivalent to a row of data for the overall operation

Data Access classes:

is to put some operations on the database, write it to a class separately, and block it into some way, waiting for the call

Three-tier development:

Interface Layer-UI layer

Business Logic Layer-C # code section

Data access Layer-entity classes and data access classes

Is that the project can be carried out in three parts at the same time, once the layout, while writing methods and packages, write the code again, and then by the call will be a few parts of the union. Instead of having to write all of the code into the same class, it's good to find the right place when the program goes wrong.

Entity class Encapsulation

public class Student

{

private string _code;

<summary>

Student number

</summary>

public string Code

{

get {return _code;}

set {_code = value;}

}

}

A new student class was created, encapsulating the member variable code.

A Select method is written in the data access class

public bool Select (string Scode)

{

BOOL has = false;

Cmd.commandtext = "Select *from Student where Code = @a";

Cmd. Parameters.clear ();

Cmd. Parameters.Add ("@a", Scode);

Conn. Open ();

SqlDataReader dr = cmd. ExecuteReader ();

if (Dr. HasRows)

{

has = true;

}

Conn. Close ();

return has;

}

Wait for the program class to call

Three-tier development of entity classes and data access classes

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.