ADO. NET and SQL Server

Source: Internet
Author: User

ADO. NET is a collection of classes that are used to connect to a database. The following describes the classes involved in connecting to SQLServer. Summary: (click the image to view the big picture) 1. The SqlConnection class connects to the SQL Server database and connects to the specified database based on the connection string information. Code 1 [vb] Dim objConnection As SqlConnection = New SqlConnection ("Server =; DataBase =; user ID =; Password =;") objConnection. open () 'Open the connection objConnection. close () 'closes connection 2. The SqlCommand class selects, inserts, updates, and deletes data by executing the corresponding command. 1) Connection property this property is set to a SqlConnection. Code 2 (connect to code 1) [vb] <span style = "font-size: 18px;"> Dim objCommand As SqlCommand = New SqlCommand () objCommand. connection = objConnection </span> 2) The CommandText attribute specifies the SQL statement or stored procedure code to be executed. 3 (Code 2) [vb] <span style = "font-size: 18px; "> objCommand. commandText = "insert into User_Info" & "user_Name, user_Id, user_PassWord" & "VALUES ('lishuang ', '12', '1')" </span> 3) parameters set code 4 (Code 3) [vb] www.2cto.com <span style = "font-s Ize: 18px; "> objCommand. parameters. add ("@ u_name", txtName. text) objCommand. parameters. add ("@ u_pw", txtPW. text) objCommand. parameters. add ("@ u_id", txtId. text) </span> the "@ u_pw" in the Code is called a placeholder. The @ variable must be filled with parameters. The add method accepts the object added by the parameter name and waist. 4) The statement executed last by the ExecuteNonQuery method inserts the information into the database for update. [Vb] <span style = "font-size: 18px;"> objCommand. executeNonQuery () </span> 3. The SqlDataAdapter class only supports the configuration connection of the SQLServer database and serves as a bridge between the data source and the Data Object Dataset. The SelectCommand attribute in the class is used to save the sqlcommand data retrieved from the data source, and then save the result to dataset. 4. DataSet is used to store the data retrieved from the data storage and stored in the memory. The data in Dataset is disconnected from the data source and can be operated independently of the database. Database connection steps: 1. Connect to the database and use SqlConnection to configure the connection string. 2. Execute the SQL statement and use SqlCommand command 3 to read data. Use DataReader4 to store content and use DataSet.

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.