0% found this document useful (0 votes)
35 views

Database Save

The procedure declares a DataRow variable to hold a new row. It uses a With statement to add the text from two text boxes to fields in the new row, which is then added to the dataset's table. The dataset is then updated back to the "ScoresTable" in the database using the DataAdapter's Update method.

Uploaded by

sedmondsbrown
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views

Database Save

The procedure declares a DataRow variable to hold a new row. It uses a With statement to add the text from two text boxes to fields in the new row, which is then added to the dataset's table. The dataset is then updated back to the "ScoresTable" in the database using the DataAdapter's Update method.

Uploaded by

sedmondsbrown
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 1

SEB’s VB.

NET Guide

Saving Back to a Database


To save back to the database the data to be added needs to be assigned to
a new row in the database and the database needs to be updated.

Example:

Private Sub pUpdate( )1


Dim objRow as Data.DataRow2
With3 objDS.Tables(0)
objRow = .NewRow4
objRow(“PlayerName”5) = txtName.text6
objRow(“Score”) = txtScore.text7
.Rows.Add(objRow)8
End With9
objDA.Update10(objDS, “ScoresTable”11)
End Sub

1
Declares the procedure pUpdate
2
Declare a variable to store the row of type Data.DataRow

3
The WITH statement allows what follows to be abbreviated so that a .
without preceding text will be replaced by the WITH content eg:
.NewRow will be replaced by objDS.Tables(0).NewRow
4
A new row is assigned to the variable
5
The field should relate to the field in the database
6
The text contents of a text box storing the player name is assigned to the
field PlayerName of the new row
7
The text contents of a text box storing the player score is assigned to the
field Score of the new row
8
The new row is added to the dataset (DS)
9
Identifies the end of the WITH statement. From this point, a . without
preceding text will be treated as an error
10
Saves the dataset back to the specified table in the database
11
The table name in the database

Page 1 of 1

You might also like