ADO SQL Property Extension ———— Multi-table group composition new more complete table

Source: Internet
Author: User

Create DatabaseGuoji--set up a databaseGo UseGuojiGoCreate TableXinxi--Establish Table I(Namevarchar( -), Minzuvarchar( -))Insert  intoXinxiValues('Lisi','101');Insert  intoXinxiValues('Wangwu','102');Insert  intoXinxiValues('Zhaoliu','103');Select *  fromXinxiGoCreate TableMinz--set up table two(Mcodevarchar( -), Mnamevarchar( -))Insert  intoMinzValues('101','Han');Insert  intoMinzValues('102','Manchu');Insert  intoMinzValues('103','Tibetan');GoSelect *   fromMinz

Requirements: Query form One, the national part with the Han show out!!!

//Xinxi The manifest of the table
UsingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;namespaceBiao. app_code{ Public classXinxi {Private string_name; Public stringName {Get{return_name;} Set{_name =value;} } Private string_minzu; Public stringMinzu//use this to receive data { Get{return_minzu;} Set{_minzu =value;} } Public stringMinzustr//with this output data { Get{minzdata n=NewMinzdata (); stringm =N.mname (_minzu); returnm; } }

//Data data access classes for Xinxi tablesusingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;usingSystem.Data.SqlClient;namespaceBiao. app_code{ Public classXinxidata {SqlConnection CNN=NULL; SqlCommand cmd=NULL;  PublicXinxidata () {CNN=NewSqlConnection ("server=.; Database=guoji;user=sa;pwd=123"); CMD=CNN.        CreateCommand (); }         PublicList<xinxi>Select()//query All information, put the information in the collection{Xinxi x=NULL; List<xinxi> list =NewList<xinxi>(); Cmd.commandtext="SELECT * from Xinxi"; Cnn.            Open (); SqlDataReader SS=cmd.            ExecuteReader (); if(ss. HasRows) { while(ss. Read ()) {x=NewXinxi (); X.name= ss["name"].                    ToString (); X.minzu= ss["Minzu"].                    ToString (); List.                ADD (x); }            }            Else{Console.WriteLine ("This table is empty, no data! "); } CNN.            Close (); returnlist; }

//Minz The manifest of a tableusingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;namespaceBiao. app_code{ Public classMinz {Private string_mcode;  Public stringMcode {Get{return_mcode;} Set{_mcode =value;} }        Private string_mname;  Public stringMname {Get{return_mname;} Set{_mname =value;} }    }}
//data access classes for Minz tablesusingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;usingSystem.Data.SqlClient;namespaceBiao. app_code{ Public classMinzdata {SqlConnection CNN=NULL; SqlCommand cmd=NULL;  PublicMinzdata () {CNN=NewSqlConnection ("server=.; Database=guoji;user=sa;pwd=123"); CMD=CNN.        CreateCommand (); }         Public stringMname (stringCode//Check the name according to the number        {                        stringA ="< no >"; Cmd.commandtext="SELECT * from Minz where [email protected]"; Cmd.            Parameters.clear (); Cmd. Parameters.Add ("@a", code); Cnn.            Open (); SqlDataReader SS=cmd.            ExecuteReader (); if(SS. HasRows)//Do you have this data{ss.                Read (); A= ss[1].                            ToString (); }            Else{Console.WriteLine ("data table is empty"); } CNN.            Close (); returnA; }    }}
//The main function of the program classusingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;usingBiao. App_Code;namespacebiao{classProgram {Static voidMain (string[] args) {Xinxidata a=NewXinxidata (); List<xinxi> list = A.Select(); foreach(Xinxi binchList//iterate through the collection query all content{Console.WriteLine (b.name+"  "+B.minzustr);//output statements with B.minzustr} console.readline (); }    }}

Finish!!

ADO SQL Property Extension ———— Multi-table group composition new more complete table

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.