Function:
1, there is a reference to the anti-
Public data type function name (data type parameter name)
{
return data type;
}
2, there is no anti-
public void function name (data type parameter name)
{
}
3. No reference, no anti-
public void function name ()
{
}
4, no reference and anti-
Public data type function name ()
{
return data type;
}
Function call:
Program P = new program ();
P. function name ();
The data access class is exactly the same as this invocation method, and the only difference is that the class name is different.
Public list<users> Select ()
{
Generic collection, placing all users Data Objects
list<users> list = new list<users> ();
Cmd.commandtext = "Select *from Users";
Conn. Open ();
SqlDataReader dr = cmd. ExecuteReader ();
if (Dr. HasRows)//If the data table has data
{
while (Dr. Read ())//loop through all data
{
Create a Users object without reading a row of data
Users u = new users ();
U.username = dr["UserName"]. ToString ();
U.password = dr["PassWord"]. ToString ();
U.nickname = dr["nickname"]. ToString ();
U.sex = Convert.toboolean (dr["Sex"]);
U.birthday = Convert.todatetime (dr["Birthday"]);
U.nation = dr["Nation"]. ToString ();
Notice that in the loop, each object that is made is put into the collection
List. ADD (U);
}
}
Conn. Close ();
return list;
}
list<users> Ulist = new Usersdata (). Select ();
if (Ulist.count > 0)
{
foreach (Users u in Ulist)//traversal
{
Console.WriteLine (u.username + "+ U.password +" "+ U.nickname +" "+ u.sex +" + u.birthday + "" + u.nation);
}
}
Console.readkey ();
function review and data access class query