Asp.net sqlconnection class and sqlcommand class Abstract

Source: Internet
Author: User

"Ado.net 2.0 technical insider

Sqlconnection

A class specifically designed to communicate with a Microsoft SQL Server database. It represents the connection to the database and serves as the starting point for creating queries and transactions.

Example:

 

StringStrconn;

Strconn= @"Data Source =. \ sqlexpress;" + "Initial catalog = northwind; intergrated SECURITY = true;"

Sqlconnection CN= NewSqlconnection (strconn );

 

Open the sqlconnection object:

 

CN. open ();

Close the sqlconnection object:

 

 
CN. Close ();

 

Sqlcommand class

In the ADO. Net object model, the sqlcommand class is used to execute queries.

The sqlcommand object allows different types of queries in the execution queue. Some sqlcommand object classes use result sets to obtain data, while others modify the content or structure of the data storage area.

 

Create a sqlcommand object

You can create a sqlcommand object in three ways.

Example:

 

 String  Strconn, strsql;

Strconn = @" Data Source =. \ sqlexpress; " + " Initial catalog = northwind; trusted_connection = yes; " ;

Strsql = " Select customerid, companyName from MERs " ;

Sqlconnection CN = New Sqlconnection (strconn );

CN. open ();

Sqlcommand cmd;



// Use a non-parameter Constructor

CMD = New Sqlcommand ();

Cmd. Connection = CN;

Cmd. commandtext = Strsql;



// Using parameterized Constructors

CMD = New Sqlcommand (strsql, CN );



// Use the createcommand method of the connection object

CMD = CN. createcommand ();

Cmd. commandtext = Strsql;

"

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.