Ado. Net (iv)--extended attributes and profile applications

Source: Internet
Author: User

One, extended properties

Processing: A foreign key relationship will be codenamed information processing into the original text, so that users can read (rough explanation)

Leveraging extended Attributes

such as: The National column in the info table shows the national name of the national code processed into the nation table.

Need to extend a property in the info class that displays the nation name

The code shows:

Step one: Construct a code name change method in Nationda

 Public stringNationname (stringcode) {_cmd.commandtext="Select Name from Nation where [email protected]"; _cmd. Parameters.addwithvalue ("@code", code); _conn.            Open (); _DR=_cmd.            ExecuteReader (); if(_DR. HasRows) {_dr.                Read (); return_dr[0].            ToString (); }            Else            {                return "Han"; } _conn.        Close (); }

Step Two:

 public  class   Info { //  Extended Name Family Name property  public  string   Nationname { get   = new   Nationda ();  return  da. Nationname (this . Nation); // this keyword, does the object have a nation   

Ii. configuration Files (app. config)

Change the computer, the database name is not the same, in order to let other users can also run, the data connection written in the configuration file, easy to modify

Cases:

In app. config:

<?xml version="1.0"encoding="Utf-8"?><configuration> <startup> <supportedruntime version="v4.0"sku=". netframework,version=v4.5"/> </startup>//Key Configuration name<appSettings> <add key="connstring"Value="server=.; Database=mydb;user=sa;pwd=123"/> </appSettings></configuration>

In the Data connection class:

 public  class   Dbconnect { private  static  string  connstring = System.configuration.configurationsettings.appsettings[ " connstring    public  static   SqlConnection Conn { get   return  new   SqlConnection (connstring); }        }    }

A lower version can be used with this method, and a higher version can be changed as prompted:

User Modification Method:

Find the second file first:

Then, open the changes with Notepad.

Ado. Net (iv)--extended attributes and profile applications

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.