Imports System.Data.OleDb
Public Class
Form1
Inherits
System.Windows.Forms.Form
'Notice these are Global within the form...
Dim objConn
As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;DATA
SOURCE=" & "c:\inetpub\wwwroot\cp\cp.mdb")
Dim
objCommand As New
OleDbCommand()
Dim objDa As New OleDbDataAdapter()
Dim objDs As New DataSet()
Dim
objCommandBuilder As OleDbCommandBuilder
Private Sub Form1_Load(ByVal sender As
System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Important to
have primary key in select statement...
objCommand.CommandText = "Select *
From Candidate order by lname"
objCommand.Connection = objConn
objDa.SelectCommand = objCommand
objDa.Fill(objDs,
"Candidate")
objConn.Close()
objCommandBuilder
= New OleDbCommandBuilder(objDa)
'Set up
TextBox DataBindings... ******************************************************
txtSsnTypeLev.DataBindings.Add("Text",
objDs.Tables("Candidate"), "SsnTypeLev")
txtFirst.DataBindings.Add("Text",
objDs.Tables("Candidate"), "Fname")
txtLast.DataBindings.Add("Text",
objDs.Tables("Candidate"), "Lname")
'************************************************************************************
End Sub
Private Sub cmdNext_Click(ByVal sender As
System.Object, ByVal e As
System.EventArgs) Handles cmdNext.Click
'Next
Button...
BindingContext(objDs.Tables("Candidate")).Position
+= 1
End Sub
Private Sub cmdPrevious_Click(ByVal sender As
System.Object, ByVal e As
System.EventArgs) Handles cmdPrevious.Click
'Previous
Button...
BindingContext(objDs.Tables("Candidate")).Position
-= 1
End Sub
Private Sub cmdUpdate_Click(ByVal sender As
System.Object, ByVal e As
System.EventArgs) Handles cmdUpdate.Click
'Update Button...
'Refresh
position in order to save the data you're sitting on...
BindingContext(objDs.Tables("Candidate")).Position
= BindingContext(objDs.Tables("Candidate")).Position
'Update The
Dataset...
objDa.Update(objDs.Tables("Candidate"))
End Sub
Private Sub cmdDelete_Click(ByVal sender As
System.Object, ByVal e As
System.EventArgs) Handles cmdDelete.Click
'Delete
Button...
BindingContext(objDs.Tables("Candidate")).RemoveAt(BindingContext(objDs.Tables("Candidate")).Position)
End Sub
Private Sub cmdAdd_Click(ByVal sender As
System.Object, ByVal e As
System.EventArgs) Handles cmdAdd.Click
'Add
Button...
BindingContext(objDs.Tables("Candidate")).AddNew()
End Sub
Private Sub cmdFilter_Click(ByVal sender As
System.Object, ByVal e As
System.EventArgs) Handles cmdFilter.Click
'Filter the
records in a dataset...
objDs.Tables("Candidate").DefaultView.RowFilter
= "LName like '%" & txtFilter.Text & "%'"
If BindingContext(objDs.Tables("Candidate")).Position
= -1 Then
MessageBox.Show("No
Reords Found")
objDs.Tables("Candidate").DefaultView.RowFilter
= "LName like '%'"
End If
End Sub
Private Sub cmdFind_Click(ByVal sender As
System.Object, ByVal e As
System.EventArgs) Handles cmdFind.Click
'Find a
record in the dataset...
'You MUST be
sorted on the field you are lookig for....
objDs.Tables("Candidate").DefaultView.Sort
= "Fname"
'Find the
row...
Dim x As Integer = objDs.Tables("Candidate").DefaultView.Find(txtFind.Text)
If x
<> -1 Then
'Move to
the row...
BindingContext(objDs.Tables("Candidate")).Position
= x
Else
MessageBox.Show("First
Name, " & txtFind.Text & " Not Found")
End If
End Sub
End Class