SqlCommand, SqlDataAdapter, DataSet learning record-turn from Kaisir

Source: Internet
Author: User

SqlConnection database Connection object: Only joins for other operations SqlDataAdapter data adapter object, which is to execute a query statement (SELECT statement) with a certain SqlConnection, and put it in a dataset SqlCommand data Command object (select,insert,delete,update, etc.) sqlcommand.parameter attribute pass SQL parameter executescalar: Executes the query, returns a single field, For example, the sum of the results, average, the maximum minimum value, and so on ExecuteReader perform a fast read-ahead query, generally to a single record of multiple fields query, multiple records can also,

The popular point is that it's usually the case:

Datasets and SqlDataAdapter are used together, there is no SqlCommand what, the general role is to show the information of a table, such as displayed on the GridView or the like

ExecuteNonQuery and SqlCommand together, there is no dataset and SqlDataAdapter what happened, usually used in the data to increase, modify, delete, note that the query can not use it

To say that query SqlDataReader and SqlCommand use, is used to query, I think you mean, according to my understanding, query a small amount of data when using SqlDataReader more convenient and flexible, high efficiency, such as querying a row of data and the like

There's also a executescalar that works with SqlCommand. Returns a single value, such as an aggregate function for a SQL statement such as SUM, total rows, and so on, such as Select COUNT (*) from table name 1

SqlConnection represents an open connection to a SQL Server database.

System.Data.SqlClient.SqlConnection

The SqlConnection object represents a unique session with a SQL Server data source. For a client/server database system, it is equivalent to a network connection to the server. SqlConnection is used with SqlDataAdapter and SqlCommand to improve performance when connecting to a Microsoft SQL Server database. For all third-party SQL server products and other data sources that support OLE DB, use OleDbConnection.

SqlDataAdapter represents a set of data commands and a database connection for populating a dataset and updating a SQL Server database.

System.Data.SqlClient.SqlDataAdapter

SqlDataAdapter is a bridge between the dataset and SQL Server that is used to retrieve and save data. SqlDataAdapter map Fill by using the appropriate Transact-SQL statements on the data source to change the data in the dataset to match the data in the data source, and Update to change the data in the data source to match the dataset The data in the database) to provide this bridge.

SqlDataAdapter is used with SqlConnection and SqlCommand to improve performance when connecting to a Microsoft SQL Server database. To access other data sources, you can use OleDbDataAdapter and the OleDbCommand and OleDbConnection associated with them.

SqlDataAdapter also includes SelectCommand, InsertCommand, DeleteCommand, UpdateCommand, and TableMappings properties, making it easier to load and update data.

SqlCommand represents a Transact-SQL statement or stored procedure to be executed against a SQL Server database.

System.Data.SqlClient.SqlCommand

SqlCommand specifically provides the following methods for executing commands on a SQL Server database:

ExecuteReader executes the command that returns the row. To improve performance, EXECUTEREADER uses Transact-SQL sp_executesql system stored procedure invoke commands. Therefore, if you are using a command such as a Transact-SQL SET statement, ExecuteReader may not get the expected effect.

ExecuteNonQuery executes commands such as Transact-SQL INSERT, Delele, UPDATE, and SET statements.

ExecuteScalar retrieves a single value (such as an aggregated value) from the database.

ExecuteXmlReader sends CommandText to Connection and generates a XmlReader object.

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.