What's the difference between SqlCommand and SqlDataAdapter?

Source: Internet
Author: User

Turn:

because the dataset is offline, the SqlDataAdapter object is a bridge between the dataset and the database, and all operations on the dataset (fill, update, etc.) are passed through hisThere are two ways to access ADO data:1. Offline-through a dataset, then offline Add, delete, change, and finally through the SqlDataAdapter resolution to the database2. Direct database Operation SqlCommand (Update,insert,delete)

SqlCommand is an order, you can use it to execute SQL commands

SqlDataAdapter is a data adapter, which is a set of objects used to communicate between a data source and a dataset SqlCommand corresponding Datereader

SqlDataAdapter corresponding DataSet SqlCommand is a C # object dealing with SQL database, almost all SQL database operations need to use this object to implement, but its function is limited, but simply to implement the interface with SQL database;

SqlDataAdapter is a powerful SQL data adapter and is also used to manipulate SQL databases, but its operations are implemented through SqlCommand (the type of a Property object is SqlCommand), which means You can think of SqlDataAdapter as a sqlcommand! that encapsulates and enhances a few special functions. SqlCommand and the command of the ADO era, SqlDataAdapter is a new thing in ADO, which works with datasets. In fact, a dataset is like a small database that resides in memory, and there can be more than one DataTable in a dataset that can be associated with one another, just like a table in a database! SqlDataAdapter's role is to extract data from the database and put it in a dataset, and when the data in the dataset changes, SqlDataAdapter updates the data in the database. To ensure that the data in the database is consistent with the data in the DataSet!

In the words of Microsoft Consultant: DataAdapter is like a spade, it is responsible for the data from the database "shovel" into the dataset, or the data from the dataset "shovel" into the database!

-----------------------------------------

SqlDataReader can only be read sequentially, can not modify the database before the program is not finished to keep the connection SqlDataAdapter once read out, you could put in the dataset. Can be used to modify the database

What's the difference between SqlCommand and SqlDataAdapter?

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.