C # learning notes-ADO. net

Source: Internet
Author: User

See a very good ADO. netArticleFor the first time, I saw this clearly. Haha, it's from sugar-★-Sugar http://www.cnblogs.com/jane_shi/.

"

Ado. Net has two connection modes: No connection mode and connection mode. The relationship between them is as follows:

1. If we regard the database as a large pool, connection is the tap that is put into the water. It plays a key role. Only when it is connected can we draw water, that is to say, data can be extracted from the database. It is a connection object. It provides four types of database access objects:
1. SQL Server databaseProgramIn the namespace of system. Data. sqlclient;
2. ODBC data provider, located in the system. Data. ODBC namespace;
3. oledb data provider, located in the namespace of system. Data. oledb;
4. The Oracle Data Provider is located in the namespace of system. Data. oracleclient.

When using connection, we usually have to call the open object to open the database. After use, you need to close the database. In this case, you can use the close () and dispose () objects to close the database. The difference between the two is that the close method is used to close a connection, the dispose method not only closes a connection, but also clears the resources occupied by the connection. When close () is used to close the connection, you can call the Open Method to open the connection without generating an error. If you use the dispose method to close the connection, you cannot use the open method to open the connection again, the connection must be reinitialized and then enabled.

 

2. The command object is like a pumping machine. It provides power and execution methods for pumping, and uses the "faucet" to reverse the water to the above pipe. It is a data command object. Its main function is to send SQL statements for queries, updates, deletions, and modifications to databases. Command objects include sqlcommand, oledbcommand, odbccommand, and oraclecommand );

The command object has three SQL statements:
1. excutenonquery method-execute an SQL statement and return the number of affected rows. When SQL command is used to send an add, delete, or modify command to the database, it is usually used to execute the SQL statement sent.
2. executereader method-execute an SQL statement and generate an instance of the sqldatareader object containing data. The returned value is a sqldatareader object.
3. executescalar method-execute an SQL statement and return the first column in the first row of the result set. The return value is usually the first column or null value in the first row of the result set (if the result set is empty ).

 

3. The dataadapter and datareader Objects Act as water transmission tasks. And act as a bridge. The dataadapter object is like a pipe, which uses an engine to send water to a reservoir for storage. The datareader object is also a type of water pipe. Unlike the dataadapter object, it does not send water to the reservoir, but directly delivers water to users who need water, so it is faster than turning around in the reservoir.
1. the datareader object is a data reader object that provides a cursor that is read-only. If the application needs to retrieve the latest data from the database each time, or only needs to read the data quickly, it does not need to modify the data, you can use the datareader object to read data. Different types of datareader objects are available for different connections.
To read data from a data table, use the executereader method. For each associated sqlconnection, only one sqldatareader can be opened at a time. Before the first one is closed, any attempt to open another will fail.
2. The dataadapter object is a data adapter object that serves as a bridge between dataset and the data source and is used for intercommunication with the data source. It provides the following four attributes:
1>. sqlcommand attribute: used to send query SQL statements to the database;
2>. deletecommand attribute: used to send a delete SQL statement to the database;
3>. insertcommand attribute: used to send query SQL statements to the database;
4>. updatacommand attribute: Send an update statement to the database;
There are several important methods in dataadapter:
1>. Fill dataset with data in the fill method.
Fill the dataset with the fill method of the dataadapter object. The connection object associated with the SELECT command must be valid, but you do not need to open it. Dataset objects are like small databases stored in memory. It can contain data tables, data columns, data rows, views, constraints, and relationships.

2> update the database. (In this case, dataadapter calls the deletecommand, insertcommand, and updatecommand attributes );
You can use the updata method of the dataadapter object to update the modified data in dataset to the database in a timely manner.

 

My friend told me that the learning is still well written, and I can record the difficulties I encountered during the learning process and the methods for solving the problems at any time. I will take a note of every knowledge point. I personally think it is more feasible. It is better than I have been confused once. Hey hey, so I got this note and will write it again later... As the content in this article is all typed by your own hand, it is not copied or pasted, so please forgive me for any write errors. Thank you...

 

"

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.