Basic methods of using Ado.net

Source: Internet
Author: User

Ado. NET as a tool in vb.net, with a considerable number of related objects, first of all the concept of some objects to explain:
(1) ADOConnection: This object represents an exact connection to a database, and a user can use an instance of this object by opening and closing a connection.
(2) Adocommand: This class represents an SQL command that a user will make to a database, it can return a value, or it can return a null value.
(3) Adodatasetcommand: Provides a bridge to the delivery of data in a database or a local data set.
(4) DataSet: A table representing one or more databases, or a collection of data returned after a query from a local database.
(5) DataTable: A separate table that is returned from a database or a query.
(6) DataRow: A separate column in a DataTable.
1. Connect a database
To connect to a database, a user can create a string of connection information specifically for that database. For example, to access an Access database, the concatenated string can be written as:

2. Reading data from a data table
To read data from a data table, users can create a adocommand and contain SQL expressions and connections with the appropriate parameters.


The user can then simply tell the command object to load the DataSet object through connection. The user must indicate the table name of the FillDataSet method action, as in the following code:

3. Execute a query
Executing a SELECT query is similar to the code above, except that it is more complex on a SQL query statement, as shown in the following code for the selection relationship:

4. Delete the contents of a table
Users can delete the contents of a table by using the delete * from table SQL expression. However, since there is no select expression to contact a local table, users can use the ExecuteNonQuery method of the Adocommand object:
Public Sub Delete ()

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.