Public ds_Employee As DataSet = New DataSet()
Dim a As Integer 'the index of the record we are seeing
Dim count_Employees As Integer 'the number of records
Sub sFill()
txtShortKey.Text = ds_Employee.Tables(0).Rows(a).Item("sKey")
txtName.Text = ds_Employee.Tables(0).Rows(a).Item("Name")
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
ds_Employee.ReadXml("C:\ds_Employees.xml", XmlReadMode.Auto)
'counts the records
count_Employees = ds_Employee.Tables(0).Rows.Count
End Sub
Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
Try
' Update the database with the changes made to the local resident DataSet.
Dim newRow As DataRow
newRow = ds_Employee.Tables(0).NewRow()
newRow("sKey") = txtShortKey.Text
newRow("Date") = txtName.Text
ds_Employee.Tables(0).Rows.Add(newRow)
ds_Employee.WriteXml("C:\ds_Employee.xml", XmlWriteMode.IgnoreSchema)
count_Employees = count_Employees + 1
a = 0
MessageBox.Show("The Employee is successfully updated.", _
"Update", MessageBoxButtons.OK, _
MessageBoxIcon.Information)
Catch ex As Exception
MsgBox("Error with the databindings: " + ex.Message)
End Try
End Sub
Private Sub btnSaveEdit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSaveEdit.Click
'save edit
ds_Employee.Tables(0).Rows(a).Item("sKey") = txtShortKey.Text
ds_Employee.Tables(0).Rows(a).Item("Name") = txtName.Text
ds_Employee.WriteXml("C:\ds_Employees.xml", XmlWriteMode.IgnoreSchema)
MessageBox.Show("The Employee Details is successfully updated.", _
"Update", MessageBoxButtons.OK, _
MessageBoxIcon.Information)
End Sub
Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete.Click
'delete
If MessageBox.Show("Are you sure you want to delete this from the database?", "Deleteing", _
MessageBoxButtons.YesNo, MessageBoxIcon.Question) _
= Windows.Forms.DialogResult.Yes Then
'update employee
Try
ds_Employee.Tables(0).Rows(a).Delete()
count_Employees = count_Employees - 1
a = 0
ds_Employee.WriteXml("C:\ds_Employees.xml", XmlWriteMode.IgnoreSchema)
Catch ex As Exception
MsgBox("Error with the databindings: " + ex.Message)
End Try
End If
End Sub
Private Sub btnFind_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFind.Click
For b = 0 To count_Employees - 1
If ds_Employee.Tables(0).Rows(b).Item("sKey").ToString.ToUpper Like ((txtShortKey.Text.ToUpper) & "*") Then
a = b
sFill()
Exit For
End If
Next
End Sub