As we all know, the biggest advantage of ADO. NET over ADO is that the data update and modification can be performed when it is completely disconnected from the data source, and then the data update is passed back.
Data source. This greatly reduces the occupation of Database Server resources due to excessive connections. The following is an example in my book ADO. NET practical guide.
The usage of ADO. NET.
Imports System. Data. SqlClient
Imports System. Data
Imports System. Data. Common
Public Class Form1
Inherits System. Windows. Forms. Form
Private Sub button#click (ByVal sender As System. Object, ByVal e As System. EventArgs) Handles Button1.Click
Dim conn As New SqlConnection ("data source = localhost; initial catalog = StudentCourse ;"&_
"User ID =; Password = ;")
Dim ds As New DataSet
Try
Conn. Open () 'Open conn before forming the SqlDataAdapter
Dim daAuthors As New SqlDataAdapter ("Select * From SC", conn)
Dim bldr As New SqlCommandBuilder (daAuthors)
DaAuthors. Fill (ds, "SC ")
Conn. Close () 'closes the connection After ds is filled, and then performs operations on ds.
Dim tbl As New DataTable
Tbl = ds. Tables ("SC ")
Dim rowVals (3) As Object
RowVals (0) = "5"
RowVals (1) = "00003"
RowVals (2) = "0001"
RowVals (3) = 99
Dim insertedRow As DataRow
InsertedRow = tbl. Rows. Add (rowVals) 'Add a row
Tbl. Rows (0). Delete () 'Delete a row
Tbl. Rows (1). BeginEdit ()
Tbl. Rows (1) ("score") = 89 'modify a row
Tbl. Rows (1). EndEdit ()
Conn. Open ()
DaAuthors. Update (ds. Tables ("SC") 'must enable the connection when the result is returned to the data source. update
Conn. Close ()
Catch ex As Exception
MessageBox. Show (ex. Message)
End Try
End Sub
End Class