ADO. NET basics and ado.net Basics
* The program needs to interact with the database through ADO. NET, through ADO. NET can execute SQL in the program, ADO.. NET provides unified operation interfaces for different databases.
1. Connect to SQLServer
- Connection string. The program uses the connection string to specify the server to be linked to, the database of the instance, and the username and password.
In practical applications, add the <connectionStrings> node to the configuration file and add the string <add name = "AA" connectionString = "xxxxxxx"/>. For details, refer to the following:
<ConnectionStrings>
<Add name = "db_user" connectionString = "server =.; database = DB_USERS; uid = sa; pwd = Password_1"/>
</ConnectionStrings>
Then add a SQLHelper class and define a method to obtain the link string, such:
Note: To use the ConfigurationManager class, you must add a reference to the System. configuration assembly. And add a namespace reference. You cannot just add the System. configuration namespace, instead of referencing the System. configuration assembly.
Public static string GetConnectionString ()
{
Return ConfigurationManager. ConnectionStrings ["db_user"]. ConnectionString;
}
In ADO. NET, a connection is created to SQL Server through the SqlConnection class. SqlConnection represents a database connection, and resources such as links in ADO. NET all implement the IDisposable interface.