Here the main record in the learning process of the use of configuration files, because it is from the computer room reconfiguration contact, the computer room in the form as an example. one, where the holy.
The application configuration file contains application-specific settings. This file contains configuration settings that the common language runtime reads, such as assembly binding policies, remoting objects, and so on, and settings that the application can read. The name and location of the application configuration file depends on the application's host, and in VS, the name of the profile is an application with a. config extension. [MSDN]
Using the configuration file is because you want to thin the D layer of the three-tier architecture and use it in SqlHelper, you need to define the variable to get the connection string for the database.
The correct code is as follows
Imports system.configuration ' Configure
Private ReadOnly connstr as String = System.Configuration.ConfigurationManager.AppSettings ("connstr") ' Gets the connection string for the database
Two, the problem
1, the ConnectionString property has not been initialized
Description: Breakpoint debugging, ConnStr for nothing, can not get the database string, may be the reason for the configuration file.
Resolve: Check the contents of the configuration file, are all written correctly. 2, ConfigurationManager is not a member of configuration
Description: ConfigurationSettings. AppSetting can be written out smoothly, but it is obsolete.
Resolution: Re-referencing System.Configuration.dll.
Then add the Imports System.Configuration in the code.
Third, summary
After solving the problem, I think it takes a little more time, but to solve the problem, to find the answer, and incidentally to understand him and some other things, very fulfilling. Once again the problem and the mistake, do not be afraid, the face always lets you see the different scenery.