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