1. Right-click the "Reference" entry in the "Solution Explorer" box and add the. NET system. configuration. dll service file.
2. Add a namespace: using system. configuration;
Add the app. config file.CodeIs:
<? XML version = "1.0" encoding = "UTF-8"?>
<Configuration>
<Configsections>
</Configsections>
<Connectionstrings>
<Add name = "connectionstring"
Connectionstring = "DSN = Excel files; DBQ = c: \ bin \ debug \ information record .xlsx; defaultdir = c: \ bin \ debug; driverid = 1046; maxbuffersize = 2048; pagetimeout = 5"
Providername = "system. Data. ODBC"/>
</Connectionstrings>
</Configuration>
3. Use the following methods to read data:
String STR = configurationmanager. connectionstrings ["connectionstring"]. connectionstring. tostring ();
Note: connectionstrings ["connectionstring"] here the brackets contain the value corresponding to name = "connectionstring,
If name = "connstr", it should be: connectionstrings ["connstr"].
In addition, if you use settings. settings in the Properties column to set the settings, you can use the following methods to read the settings:
String STR = properties. settings. Default. connectionstring;
This statement is the same as in the preceding example. Strings can be obtained.