'Declare Objects...
Dim myAdapter As OleDbDataAdapter = New OleDbDataAdapter( _
"SELECT Student_ID, Student_Fname, Student_Lname, Date_of_Birth, Address, Post_Code, Telephone_No " & _
"FROM Student", OleDbConnection1)
Dim myDS As DataSet
Dim myDV As DataView
Private Sub FillDataSetAndView()
'Initialize a new instance of the DataSet object...
myDS = New DataSet
'Set Connection and Fill DataSet object...
myAdapter.SelectCommand.Connection = OleDbConnection1
myAdapter.Fill(myDS, "Student")
'Set the DataView object to the DataSet
myDV = New DataView(myDS.Tables("Student"))
End Sub
Private Sub BindFields()
'Clear any previous bindings...
txtStudentID.DataBindings.Clear()
txtFname.DataBindings.Clear()
txtSname.DataBindings.Clear()
dtpDOB.DataBindings.Clear()
txtAddress.DataBindings.Clear()
txtPostCode.DataBindings.Clear()
txtTelephone.DataBindings.Clear()
'Add new bindings to the DataView object...
txtStudentID.DataBindings.Add("Text", myDV, "Student_ID")
txtFname.DataBindings.Add("Text", myDV, "Student_Fname")
txtSname.DataBindings.Add("Text", myDV, "Student_Lname")
dtpDOB.DataBindings.Add("Text", myDV, "Date_of_Birth")
txtAddress.DataBindings.Add("Text", myDV, "Address")
txtPostCode.DataBindings.Add("Text", myDV, "Post_Code")
txtTelephone.DataBindings.Add("Text", myDV, "Telephone_No")
End Sub
Private Sub btnSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSearch.Click
'Fill the dataset and bind the field...
FillDataSetAndView()
BindFields()
End Sub