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