function review and data access class query

Source: Internet
Author: User

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

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.