ADO. NET basics and ado.net Basics

Source: Internet
Author: User

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.

 

Related Article

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.