ASP.net 2.0 Execute database Operations Command bis

Source: Internet
Author: User
Tags bool numeric value

SqlDataReader class

You can read rows from a SQL Server database with the SqlDataReader class object, and read rows from a database that supports OLE DB with the OleDbDataReader class object, such as Oracle and access ; Read rows from an ODBC-enabled database using the OdbcDataReader class object.

The DataReader object allows you to read data in a forward, read-only way, and sometimes the DataReader object is also called a hose cursor. The DataReader object uses a simplified way of reading data, but improves performance while sacrificing a lot of features. such as sorting, paging, and so on that are supported in the dataset. These features will be described in more detail in a later section.

Properties of SqlDataReader

Property Description
Depth whose return type is int, gets the value that represents the current line's embedded depth
FieldCount The return type is int to get the number of columns in the current row
Iscolsed The return type is bool, obtaining a Boolean value indicating whether to turn off data reading
RecordsAffected The return type is int, and gets the number of rows that were added, modified, or deleted by the execution SQL statement.

The method of SqlDataReader

Method Description
Reader () The return type is bool, moves the data reader to the next row of the result set, and reads the row. The Boolean value returned by this method indicates whether there are multiple rows in the result set
GetValue () Whose return type is object, returns the value of the specified column
GetValues () The return type is int, and the values of all columns in the current row are copied to the specified object array. The int that this method returns is the number of elements in the array
NextResult () The return type is bool, and the data reader is moved to the next row of the result set. The Boolean value returned by this method indicates whether there are multiple rows in the result set
Close () off SqlDataReader objects
GetInt32 (), GetChar (),
Gatedatatime (), getxxx ()
Returns the value of the specified column, and the returned type is the appropriate data type. For example, GetInt32 () returns the numeric value of an integral type. Note that if you assign a return value to a variable that does not match a type, a InvalidCastException exception is thrown

Executing a query with the ExecuteReader () method

The following is an example of executing a SELECT statement with the ExecuteReader () method. This method returns the result set with the DataReader object and can then read the rows returned by the database with this object.

Related Article

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.