Attribute expansion in entity classes, data access classes

Source: Internet
Author: User

In the class:

Using system;using system.collections.generic;using system.data.sqlclient;using system.linq;using System.Text; Namespace entity class _ Data Access class.        app_code{public class Users {SqlConnection conn = null;        SqlCommand cmd = null; Public Users () {conn = new SqlConnection ("server=.;            Database=data0928;user=sa;pwd=123 "); CMD = conn.        CreateCommand ();        } private int _ids; <summary>//IDs//</summary> public int IDs {get {return _ids ;        } set {_ids = value;}        } private string _username; <summary>///user name///</summary> public string UserName {get {ret Urn _username;        } set {_username = value;}        } private string _password; <summary>//password///</summary> public string PassWord {get {Retu RN _password;    }        set {_password = value;}        } private string _nickname; <summary>//Nickname///</summary> public string Nickname {get {Retu RN _nickname;        } set {_nickname = value;} } public string Nickanduser {get {return _nickname + "(" + _username            + ")";        }} private bool _sex; <summary>///gender///</summary> public bool Sex {get {return _sex ;        } set {_sex = value;} }//Judge is male is the public string Sexstr {get {return _sex?            "Male": "Female";        }} private DateTime _birthday; <summary>//Birthdays///</summary> public DateTime Birthday {get {RE Turn _birthday;        } set {_birthday = value;} }        //Convert a DateTime type to a String type public string Birthdaystr {get {return _BIRTHD Ay.            ToString ("yyyy mm month DD day");        }} private string _nation;  <summary>//National///</summary> public string Nation {get {return} _nation;        } set {_nation = value;} }//To display the nation with a string of public string Nationname {get {string end = "&                lt; not filled > ";                Cmd.commandtext = "Select *from Nation where nationcode = @a"; Cmd.                Parameters.clear (); Cmd.                Parameters.Add ("@a", _nation); Conn.                Open (); SqlDataReader dr = cmd.                ExecuteReader (); if (Dr. hasrows) {Dr.                    Read (); end=dr["Nationname"].                ToString (); } conn.                Close ();            return end;      }        }  private string _class; <summary>///class///</summary> public string class {get {return _class;        } set {_class = value;} }//Display the class with a string public string ClassName {get {string end = "&l                t; no class > ";                Cmd.commandtext = "Select *from Class where classcode = @a"; Cmd.                Parameters.clear (); Cmd.                Parameters.Add ("@a", _class); Conn.                Open (); SqlDataReader dr = cmd.                ExecuteReader (); if (Dr. hasrows) {Dr.                    Read (); End = dr["ClassName"].                ToString (); } conn.                Close ();            return end; }        }    }}

In the main program:

Using system;using system.collections.generic;using system.linq;using system.text;using entity Class _ Data Access class. App_code;namespace Property Extension {    class program    {        static void Main (string[] args)        {            list<users> Ulist = new Usersdata (). Select ();            Console.WriteLine ("Serial number   password   nickname   gender   Birthday   National   class");            foreach (Var u in ulist)            {                Console.WriteLine (u.ids + "+   U.password +"   "+ U.nickanduser +"   " + u.sexstr + "+   U.birthdaystr +"   "+ u.nationname +"   "+ u.classname);            }            Console.readkey ();}}}    

Attribute expansion in entity classes, 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.