Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Public Class Form1
- Dim MaxRows As Integer
- Dim inc As Integer
- Dim con As New OleDb.OleDbConnection
- Dim dbProvider As String
- Dim dbSource As String
- Dim ds As New DataSet
- Dim da As OleDb.OleDbDataAdapter
- Dim sql As String
- Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
- dbProvider = "PROVIDER=Microsoft.Jet.OLEDB.4.0;"
- dbSource = "Data Source = N:\AddressBook.mdb"
- con.ConnectionString = dbProvider & dbSource
- con.Open()
- sql = "SELECT * FROM tblCars"
- da = New OleDb.OleDbDataAdapter(sql, con)
- da.Fill(ds, "AddressBook")
- con.Close()
- MaxRows = ds.Tables("AddressBook").Rows.Count
- inc = -1
- End Sub
- Private Sub NavigateRecords()
- txtCarMake.Text = ds.Tables("AddressBook").Rows(inc).Item(1)
- txtCarModel.Text = ds.Tables("AddressBook").Rows(inc).Item(2)
- txtCarMilage.Text = ds.Tables("AddressBook").Rows(inc).Item(3)
- txtCarEngine.Text = ds.Tables("AddressBook").Rows(inc).Item(4)
- txtCarTransmission.Text = ds.Tables("AddressBook").Rows(inc).Item(5)
- txtCarFuel.Text = ds.Tables("AddressBook").Rows(inc).Item(6)
- txtCarNotes.Text = ds.Tables("AddressBook").Rows(inc).Item(7)
- End Sub
- Private Sub nextBtn_Click(sender As Object, e As EventArgs) Handles nextBtn.Click
- If inc <> MaxRows - 1 Then
- inc = inc + 1
- NavigateRecords()
- Else
- MsgBox("No More Rows")
- End If
- End Sub
- Private Sub backBtn_Click(sender As Object, e As EventArgs) Handles backBtn.Click
- If inc > 0 Then
- inc = inc - 1
- NavigateRecords()
- ElseIf inc = -1 Then
- MsgBox("No Records Yet")
- ElseIf inc = 0 Then
- MsgBox("First Record")
- End If
- End Sub
- Private Sub startBtn_Click(sender As Object, e As EventArgs) Handles startBtn.Click
- If inc <> 0 Then
- inc = 0
- NavigateRecords()
- End If
- End Sub
- Private Sub endBtn_Click(sender As Object, e As EventArgs) Handles endBtn.Click
- If inc <> -1 Then
- inc = MaxRows - 1
- NavigateRecords()
- End If
- End Sub
- Private Sub btnUpdate_Click(sender As Object, e As EventArgs) Handles btnUpdate.Click
- Dim cb As New OleDb.OleDbCommandBuilder(da)
- ds.Tables("AddressBook").Rows(inc).Item(1) = txtCarMake.Text
- ds.Tables("AddressBook").Rows(inc).Item(2) = txtCarModel.Text
- ds.Tables("AddressBook").Rows(inc).Item(3) = txtCarMilage.Text
- ds.Tables("AddressBook").Rows(inc).Item(4) = txtCarEngine.Text
- ds.Tables("AddressBook").Rows(inc).Item(5) = txtCarTransmission.Text
- ds.Tables("AddressBook").Rows(inc).Item(6) = txtCarFuel.Text
- ds.Tables("AddressBook").Rows(inc).Item(7) = txtCarNotes.Text
- da.Update(ds, "AddressBook")
- MsgBox("Data Updated")
- End Sub
- Private Sub btnAddNew_Click(sender As Object, e As EventArgs) Handles btnAddNew.Click
- btnCommit.Enabled = True
- btnAddNew.Enabled = False
- btnUpdate.Enabled = False
- btnDelete.Enabled = False
- txtCarMake.Clear()
- txtCarModel.Clear()
- txtCarMilage.Clear()
- txtCarEngine.Clear()
- txtCarTransmission.Clear()
- txtCarFuel.Clear()
- txtCarNotes.Clear()
- End Sub
- Private Sub btnCommit_Click(sender As Object, e As EventArgs) Handles btnCommit.Click
- If inc <> -1 Then
- Dim cb As New OleDb.OleDbCommandBuilder(da)
- Dim dsNewRow As DataRow
- dsNewRow = ds.Tables("AddressBook").NewRow()
- dsNewRow.Item("CarMake") = txtCarMake.Text
- dsNewRow.Item("CarModel") = txtCarModel.Text
- dsNewRow.Item("CarMilage") = txtCarMilage.Text
- dsNewRow.Item("CarEngine") = txtCarEngine.Text
- dsNewRow.Item("CarTransmission") = txtCarTransmission.Text
- dsNewRow.Item("CarFuel") = txtCarFuel.Text
- dsNewRow.Item("CarNotes") = txtCarNotes.Text
- ds.Tables("AddressBook").Rows.Add(dsNewRow)
- da.Update(ds, "AddressBook")
- NavigateRecords()
- MsgBox("New Record Added To The Database")
- btnCommit.Enabled = False
- btnAddNew.Enabled = True
- btnUpdate.Enabled = True
- btnDelete.Enabled = True
- End If
- If txtCarMake.Text = "" Then
- MessageBox.Show("Enter A Car Make Into The First Field.")
- ElseIf txtCarModel.Text = "" Then
- MessageBox.Show("Enter A Car Model Into The Second Field.")
- ElseIf txtCarMilage.Text = "" Then
- MessageBox.Show("Enter The Car Milage Into The Third Field.")
- ElseIf txtCarEngine.Text = "" Then
- MessageBox.Show("Enter The Cars Engine Into The Forth Field.")
- ElseIf txtCarTransmission.Text = "" Then
- MessageBox.Show("Enter The Cars Transmission Into The Fifth.")
- ElseIf txtCarFuel.Text = "" Then
- MessageBox.Show("Enter The Cars Full Comsumption Into The Sixth.")
- ElseIf txtCarNotes.Text = "" Then
- MessageBox.Show("Enter Any Notes For The Car Into The Last Field.")
- End If
- End Sub
- Private Sub btnDelete_Click(sender As Object, e As EventArgs) Handles btnDelete.Click
- If MessageBox.Show("Do you really want to Delete this record?",
- "Delete", MessageBoxButtons.YesNo,
- MessageBoxIcon.Warning) = Windows.Forms.DialogResult.No Then
- MsgBox("Operation Canceled")
- Exit Sub
- End If
- Dim cb As New OleDb.OleDbCommandBuilder(da)
- ds.Tables("AddressBook").Rows(inc).Delete()
- MaxRows = MaxRows - 1
- inc = 0
- da.Update(ds, "AddressBook")
- NavigateRecords()
- End Sub
- Private Sub btnClear_Click(sender As Object, e As EventArgs) Handles btnClear.Click
- btnCommit.Enabled = False
- btnAddNew.Enabled = True
- btnUpdate.Enabled = True
- btnDelete.Enabled = True
- inc = 0
- NavigateRecords()
- End Sub
- End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement