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.