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