ASP. NET learning notes-ADO. NET (1)

Source: Internet
Author: User
All the notes are from the C # Web application getting started classic.
1. Architecture of ADO. NET
The name ADO. NET does not represent the actual content-ADO originally represents ActiveX Data Obejects, but a technical name. The most common method to access a database is to first connect to the database and then use SQL statements. Different database operations have different Command object methods. For example, the ExecuteScalar () method returns an object containing values. The ExecuteReader () method is used to access the DataReader object in the result set. ExecuteNonQuery () returns an integer value, indicating the number of rows affected by the command. The DataReader object is a fast, read-only connection pointer that only returns data from the database. After obtaining the object through the ExecuteReader () method, call Read () and use its method to access the data at the current location if True is returned. The result set contains multiple data rows. You can use the following code to access each row:
Reader = command. ExecuteReader ();
While (read. Read ())
{
// Process current row
}
To access the data contained in each column unit in the current row, you can use the following method to access: (1) GetXXX () to retrieve the entered value. Methods such as GetBoolean (), GetString (), and GetInt32 () can receive column indexes as parameters and return the correct value type. For example, Response. Write (reader. GetString (0); (reader is the DataReader object of the code above, the same below ). Of course, sometimes you do not know the index but the name. You can use the GetOrdinal () method of the DataReader object to receive the column name and return the column position: int pos = reader. getOrdinal ("CategoryID"); (2) default Item attribute. You can use this attribute to directly access the column value. The parameter can be an integer index value or a String column name, the returned value is of the object type. Therefore, you need to convert the displayed data type to the required data type: int id = (int) reader ["UserId"]; or the int id = (int) reader [0]; (3) GetValues () method can fill the values in the column into the array. This method receives an object-type array and fills it with data in the current row: object [] values = new object [3]; reader. getValues (values); you can use the FieldCount attribute of DataReader to initialize this array. The code above indicates filling in the array with the first three columns of the current row.

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.