ADO. NET

Source: Internet
Author: User

ADO. NET
1.vb.net:
Vb.net does not support database operations. NET Framwork SDK for database programming class libraries and Microsoft MDAC implementation, where ADO. NET is. NET Framwork SDK is an important part. It is a general term for class libraries used to operate Numerical Control in the. NET Framwork SDK.

2.ado.net
1. namespace: reference before use
Imports system. data
Imports system. sqlclient

2.ado.net Core Content


Connection class: Establish a database connection

Dim cn As New SqlConnetion () cn. connectionString = "connection string" cn. open () or Dim conn As string = "server = liangliangPC; database = ComChargeSys; user id = sa; password = 123456" Dim cn As SqlConnetion = New SqlConnnetion (conn) cn. open ()


Command class:Perform database operations (add, delete, modify, and query)

1. Create: Dim cmd As SqlCommand = New SqlCommand (SQL, cn)
The constructor of the command object has two parameters: one is the SQL statement to be executed, and the other is the database connection object.
2. Run cmd. ExecuteNonQuery () to run the command. After executing the command, close the data connection cn. close ()


Parameter class:The base class of the parameter class to provide parameters for the data source control.

Cmd. parameters. add () add parameters to the parameter set (parameter list)
The first parameter in add is the parameter name of the added parameter, and the second is the parameter type of the parameter (the third is the length)


DataReader class:Provides a method to read rows from the SQL Server database only into the stream.

1. Create: Use cmd.exe cutereader to create a datareader object.
Dim reader As SqlDataReader = cmd. ExecuteReader ()
2. Common Methods:
SqlDataReader. read () Get Query Information
SqlDataReader. GetString () gets the string value of the specified column.
SqlDataReader. GetOrdinal () obtains the sequence number of a given column name.
SqlDataReader. GetDateTime, GetDouble, and GetInt32 access the column values of the current data type (data type conversion)

3. For example, obtaining the student's student ID and name
SDStudent. StudentNo = Trim (reader. GetInt32 (reader. GetOrdinal ("StudentNo ")))
SDStudent. StudentName = Trim (reader. GetString (reader. GetOrdinal ("StudentName ")))


DataSet class:Is a database that exists in the memory and can contain any number of datatable data.

Datatble corresponds to the table or view of a database. A datatable object contains a collection of data rows (datarow) and (datacolumn. In the first three layers, the use of datatable does not involve the need to know this for the moment. During the reconstruction of layer D, we will talk about the conversion of datatable and generic sets, detailed description at that time.


3. Summary:

These are the most basic knowledge of ado.net. In the first three layers, we can understand how to use methods in various classes and classes.

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.