Executescalar () and executenonquery Methods

Source: Internet
Author: User

The executescalar method returns the object type. This method returns the value in the first column of the First row after the SQL statement is executed. The structure of the SQL statement is unknown (it may be int, it may be char, etc.), so the executescalar method returns the most basic type object, which is the base class of all types. In other words, it can be converted to any type.

The executenonquery method is used to execute insert, delete, and update statements. Because these statements have only one result after execution: "affected ** rows ", therefore, the executenonquery method returns the number of affected rows (INT ).

Although the name of a column in SQL is of the string type, you must forcibly convert the type to access this field using datareader ["name, because datareader ["name"] is like an array, the types of each element in the array should be the same, so the element type in the array datareader [] is also defined as the object type, to facilitate conversion.

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.