Title: Add, Delete, and Edit Records
1Add, Delete, and Edit Records
- Explain the two-step approach
- The techniques for adding, deleting, and editing
records
2(No Transcript)
3A Two-Step Process
- Changes are first made to the dateset.
- Database is then updated.
Project
database
dataset
Form1 Form2
invoice
customer
1
2
customer
invoice line item
part
resides in local machine
4Initial Procedures
Private Sub Form1_Load() Handles MyBase.Load
locktextboxes() Adapter1.Fill(DataSe
t11) displayposition() End Sub
Private Sub unlocktextboxes()
TextBox1.ReadOnly False
TextBox2.ReadOnly False
TextBox3.ReadOnly False
TextBox4.ReadOnly False
TextBox5.ReadOnly False End Sub
Private Sub locktextboxes()
TextBox1.ReadOnly True
TextBox2.ReadOnly True
TextBox3.ReadOnly True
TextBox4.ReadOnly True
TextBox5.ReadOnly True End Sub
5Step 1 make changes to the dataset
6Adding a Record to the Dataset
Private Sub AddRecord_Click() Handles
AddRecord.Click generate a blank record
BindingContext(DataSet11, "vehicle").AddNew()
unlocktextboxes () End Sub
'save the newly added record to the dataset
Private Sub SaveRecord_Click() Handles
SaveRecord.Click 'this line is needed to
attach the newly added record to the dataset
BindingContext(DataSet11, "vehicle").EndCurren
tEdit() locktextboxes () End Sub
'discard the record being addded to the dataset
Private Sub DiscardAdd_Click() Handles
DiscardAdd.Click BindingContext(DataSet11
, "vehicle").CancelCurrentEdit()
locktextboxes () End Sub
7Edit the Current Record
'edit the current record Private Sub
EditRecord_Click() Handles EditRecord.Click
unlocktextboxes() End Sub
'save the changes made to the current record to
the dataset Private Sub SaveEdit_Click()
Handles SaveEdit.Click
BindingContext(DataSet11, "vehicle").EndCurrentEdi
t() locktextboxes() End Sub
'cancel the changes being made to the current
record Private Sub CancelEdit_Click()
Handles CancelEdit.Click
BindingContext(DataSet11, "vehicle").CancelCurrent
Edit() locktextboxes() End Sub
8Methods of BindingContext Object
- AddNew
- EndCurrentEdit
- CancelCurrent Edit
Step1 Make changes to the dataset
9Step 2 Update the Database
Project
database
dataset
Form1 Form2
invoice
customer
1
2
customer
invoice line item
part
resides in local machine
10Step 2
11Commit or Reject Changes to the Database
'send the changes made to the dataset to the
database Private Sub UpdateDatabase_Click()
Handles UpdateDatabase.Click
Adapter1.Update(DataSet11, "Vehicle")
End Sub
'cancel all the changes made to the dataset
since the last update Private Sub
CancelAll_Click() Handles CancelAll.Click
DataSet11.RejectChanges() End Sub