"ASP." ADO

Source: Internet
Author: User

We have been programming for so long that almost every program requires us to deal with the database, access to and processing of data are indispensable operations. In ASP. NET, it provides us with ADO, which provides access to relational data, XML, and application data, and supports a variety of development needs.  In fact, when we learn the database, and the contact with the ADO, but did not summarize, this time the study is easier to understand than before, so also summed up.  ADO. NET component separates data access and data processing, it is through two main components:. NET data provider, and a dataset to do this. Here is the overall structure of the ADO:
  ADO. NET data access is generally done in two ways: direct access through DataReader objects, and access through DataSet objects and DataAdapter objects. It contains four types of objects:
  
    • Connection, providing a connection to the data source;
    • command, database commands for returning, modifying data, running stored procedures, and sending or retrieving parameter information;
    • DataReader, providing high-performance data streams from the data source;
    • DataAdapter, which provides a bridge to the DataSet object and data, uses the command object to execute SQL commands in the data source to load the data into the DataSet object, and to keep the data changes in the DataSet object consistent with the data source.
Here is a summary of these four object one by one:(i) Connection objectFor the operation of the database, the first need to connect to the database, in ADO, the use of connection objects to connect to the database, some of the commonly used parameters include:
    • The name of the data source:sql Server database server;
    • Initial Catalog: Database name;
    • Integrated security: Determine whether the connection is secure;
    • User id:sql Server login account;
    • The login password for the PASSWORD:SQL server account.
(ii) Command objectOnce the database connection succeeds, the data in the database can be read and manipulated, primarily by executing the SQL command with the command object.SqlCommand class, I was in the machine room refactoring, there is a deeper understanding, whether it is the execution of SQL statements, or stored procedures, this is through the Command object's properties and methods to change. The following is a brief list of some of the properties and methods we have used in the machine room reconfiguration, some of which may not be understood at the time of use. Properties of the SqlCommand class:
    • CommandText: A type of string whose value can be an SQL statement, a stored procedure, or a table;
    • CommandType: Type is an enumeration type, text is an SQL statement, StoredProcedure is a stored procedure, TableDirect is the table to read;
    • Connection: Gets the SqlConnection object that uses the object to communicate with the database.
Important methods of the SqlCommand class:
    • ExecuteNonQuery: Type int, executes SQL statement with no return result;
    • ExecuteReader: Type SqlDataReader, executes a SELECT, TableDirect command, or a stored procedure with a return result;
    • CreateParameter: Creates a SqlParameter object.
Constructors for the SqlCommand class:
    • SqlCommand (): Create the object directly without parameters;
    • SqlCommand (String commandtext): Creates an object from an SQL statement;
    • SqlCommand (String Commandtext,sqlconnection conn): Creates objects based on SQL statements and data source connections;
    • SqlCommand (String commandtext,sqlconnection conn,sqltransaction Tran): Creates objects based on SQL statements, data source connections, and transaction objects;
(iii) DataReader objectIf the command object is executed with a SELECT command that returns data, the command object automatically produces a DataReader object that can be taken out of the data source and displayed to the consumer, which can read only one piece of data at a time, and can be read-only.(iv) DataAdapter objectThe DataAdapter object can be used to save and retrieve data, and its Fill method is used to populate the query results into a dataset or DataTable.In addition to the above four objects, the dataset we are more familiar with, in the machine room refactoring, we have also been useful, we have the database and data control binding, we can get a dataset, so that we access and processing data is much easier.A dataset can be seen as a data container, which is a cache of data in a variety of data sources mapped into computer memory. Has the following characteristics:
    • Independence from a variety of data sources;
    • offline and connected, which can manipulate data in the database either offline or in real-time connection;
    • It is a view of the data relationship.
The process of learning is the need for us to constantly repeat, some time is the first to learn the theory, and then slowly will be used, after the use of, I feel that they understand a bit more deeply, and sometimes they have been used, but the theoretical meaning is not clear, until later encountered the relevant theoretical knowledge of learning, Suddenly there was a feeling of epiphany. Either way, the combination of theory and practice is essential.

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

ASP. ADO

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.