command-to-image (commands)

Source: Internet
Author: User

The command object is used to execute commands for adding, deleting, changing, and checking data in the database. During the operation, the connection between the application and the database must be maintained.

  "Common Properties":

    CommandText: Gets or sets the T-AQL statement that needs to be executed against the database;

    Connection: Gets or sets the Connection object used by this example.

  "Common methods":

    ExecuteNonQuery: Executes the T-SQL statement and returns the number of rows affected;

    ExecuteReader: Executes the query command and returns the DataReader object;

    ExecuteScalar: Executes the query command and returns the first column in the first row of the query result set, ignoring the other columns or rows.

"Steps for adding , deleting , and changing a database using the Command object":

1, create connection object;

2, open the database connection;

3. Define the T-SQL statements that need to be executed; ( defines string type strings for saving T-SQL statements that need to be executed )

4, create the command object;

    "statement": SqlCommand Command object name =new SqlCommand("T-SQL statement", connection object );

5, execute the statement; ( the method is used to execute the specified T-SQL statement, returning the number of rows affected )

    statement: The name of the Command object. ExecuteNonQuery ();

6. Close the database.

"Use the Command object to query the database and return the steps for a single value operation":

  1, create connection object;

2, open the database connection;

3. Define the T-SQL statements that need to be executed; ( defines string type strings for saving T-SQL statements that need to be executed )

4, create the command object;

5, execute T-SQL statement, and receive the query results; ( the return value of the method is the first value in the query result set and requires explicit type conversions upon receipt )

    statement: TheCommand object. ExecuteScalar ();

6. Close the database.

command-to-image (commands)

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.