A classic example of getting started with ADO. net

Source: Internet
Author: User

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

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.