Developer on Alibaba Coud: Build your first app with APIs, SDKs, and tutorials on the Alibaba Cloud. Read more ＞
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 ; (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 ; 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.
This article is an English version of an article which is originally in the Chinese language on aliyun.com and is provided for information purposes only. This website makes no representation or warranty of any kind, either expressed or implied, as to the accuracy, completeness ownership or
reliability of the article or any translations thereof. If you have any concerns or complaints relating to the article, please send an email, providing a detailed description of the concern or
complaint, to firstname.lastname@example.org. A staff member will contact you within 5 working days. Once verified, infringing content will be removed immediately.
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:
and provide relevant evidence. A staff member will contact you within 5 working days.