Advertisement
Guest User

Untitled

a guest
May 6th, 2015
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.25 KB | None | 0 0
  1. Public Class Form1
  2.  
  3. Dim MaxRows As Integer
  4. Dim inc As Integer
  5. Dim con As New OleDb.OleDbConnection
  6. Dim dbProvider As String
  7. Dim dbSource As String
  8. Dim ds As New DataSet
  9. Dim da As OleDb.OleDbDataAdapter
  10. Dim sql As String
  11. Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  12.  
  13. dbProvider = "PROVIDER=Microsoft.Jet.OLEDB.4.0;"
  14. dbSource = "Data Source = N:\AddressBook.mdb"
  15.  
  16. con.ConnectionString = dbProvider & dbSource
  17.  
  18. con.Open()
  19.  
  20. sql = "SELECT * FROM tblCars"
  21. da = New OleDb.OleDbDataAdapter(sql, con)
  22. da.Fill(ds, "AddressBook")
  23. con.Close()
  24.  
  25. MaxRows = ds.Tables("AddressBook").Rows.Count
  26. inc = -1
  27.  
  28. End Sub
  29. Private Sub NavigateRecords()
  30.  
  31. txtCarMake.Text = ds.Tables("AddressBook").Rows(inc).Item(1)
  32. txtCarModel.Text = ds.Tables("AddressBook").Rows(inc).Item(2)
  33. txtCarMilage.Text = ds.Tables("AddressBook").Rows(inc).Item(3)
  34. txtCarEngine.Text = ds.Tables("AddressBook").Rows(inc).Item(4)
  35. txtCarTransmission.Text = ds.Tables("AddressBook").Rows(inc).Item(5)
  36. txtCarFuel.Text = ds.Tables("AddressBook").Rows(inc).Item(6)
  37. txtCarNotes.Text = ds.Tables("AddressBook").Rows(inc).Item(7)
  38.  
  39. End Sub
  40. Private Sub nextBtn_Click(sender As Object, e As EventArgs) Handles nextBtn.Click
  41.  
  42. If inc <> MaxRows - 1 Then
  43. inc = inc + 1
  44. NavigateRecords()
  45. Else
  46. MsgBox("No More Rows")
  47. End If
  48.  
  49. End Sub
  50. Private Sub backBtn_Click(sender As Object, e As EventArgs) Handles backBtn.Click
  51.  
  52. If inc > 0 Then
  53. inc = inc - 1
  54. NavigateRecords()
  55. ElseIf inc = -1 Then
  56. MsgBox("No Records Yet")
  57. ElseIf inc = 0 Then
  58. MsgBox("First Record")
  59. End If
  60.  
  61. End Sub
  62.  
  63. Private Sub startBtn_Click(sender As Object, e As EventArgs) Handles startBtn.Click
  64.  
  65. If inc <> 0 Then
  66. inc = 0
  67. NavigateRecords()
  68. End If
  69.  
  70. End Sub
  71.  
  72. Private Sub endBtn_Click(sender As Object, e As EventArgs) Handles endBtn.Click
  73.  
  74. If inc <> -1 Then
  75. inc = MaxRows - 1
  76. NavigateRecords()
  77. End If
  78.  
  79. End Sub
  80.  
  81. Private Sub btnUpdate_Click(sender As Object, e As EventArgs) Handles btnUpdate.Click
  82.  
  83. Dim cb As New OleDb.OleDbCommandBuilder(da)
  84.  
  85. ds.Tables("AddressBook").Rows(inc).Item(1) = txtCarMake.Text
  86. ds.Tables("AddressBook").Rows(inc).Item(2) = txtCarModel.Text
  87. ds.Tables("AddressBook").Rows(inc).Item(3) = txtCarMilage.Text
  88. ds.Tables("AddressBook").Rows(inc).Item(4) = txtCarEngine.Text
  89. ds.Tables("AddressBook").Rows(inc).Item(5) = txtCarTransmission.Text
  90. ds.Tables("AddressBook").Rows(inc).Item(6) = txtCarFuel.Text
  91. ds.Tables("AddressBook").Rows(inc).Item(7) = txtCarNotes.Text
  92.  
  93. da.Update(ds, "AddressBook")
  94.  
  95. MsgBox("Data Updated")
  96. End Sub
  97.  
  98. Private Sub btnAddNew_Click(sender As Object, e As EventArgs) Handles btnAddNew.Click
  99.  
  100. btnCommit.Enabled = True
  101. btnAddNew.Enabled = False
  102. btnUpdate.Enabled = False
  103. btnDelete.Enabled = False
  104.  
  105. txtCarMake.Clear()
  106. txtCarModel.Clear()
  107. txtCarMilage.Clear()
  108. txtCarEngine.Clear()
  109. txtCarTransmission.Clear()
  110. txtCarFuel.Clear()
  111. txtCarNotes.Clear()
  112.  
  113.  
  114. End Sub
  115.  
  116. Private Sub btnCommit_Click(sender As Object, e As EventArgs) Handles btnCommit.Click
  117.  
  118. If inc <> -1 Then
  119. Dim cb As New OleDb.OleDbCommandBuilder(da)
  120. Dim dsNewRow As DataRow
  121.  
  122. dsNewRow = ds.Tables("AddressBook").NewRow()
  123.  
  124. dsNewRow.Item("CarMake") = txtCarMake.Text
  125. dsNewRow.Item("CarModel") = txtCarModel.Text
  126. dsNewRow.Item("CarMilage") = txtCarMilage.Text
  127. dsNewRow.Item("CarEngine") = txtCarEngine.Text
  128. dsNewRow.Item("CarTransmission") = txtCarTransmission.Text
  129. dsNewRow.Item("CarFuel") = txtCarFuel.Text
  130. dsNewRow.Item("CarNotes") = txtCarNotes.Text
  131.  
  132. ds.Tables("AddressBook").Rows.Add(dsNewRow)
  133.  
  134. da.Update(ds, "AddressBook")
  135. NavigateRecords()
  136. MsgBox("New Record Added To The Database")
  137.  
  138. btnCommit.Enabled = False
  139. btnAddNew.Enabled = True
  140. btnUpdate.Enabled = True
  141. btnDelete.Enabled = True
  142.  
  143. End If
  144.  
  145. If txtCarMake.Text = "" Then
  146. MessageBox.Show("Enter A Car Make Into The First Field.")
  147.  
  148. ElseIf txtCarModel.Text = "" Then
  149. MessageBox.Show("Enter A Car Model Into The Second Field.")
  150.  
  151. ElseIf txtCarMilage.Text = "" Then
  152. MessageBox.Show("Enter The Car Milage Into The Third Field.")
  153.  
  154. ElseIf txtCarEngine.Text = "" Then
  155. MessageBox.Show("Enter The Cars Engine Into The Forth Field.")
  156.  
  157. ElseIf txtCarTransmission.Text = "" Then
  158. MessageBox.Show("Enter The Cars Transmission Into The Fifth.")
  159.  
  160. ElseIf txtCarFuel.Text = "" Then
  161. MessageBox.Show("Enter The Cars Full Comsumption Into The Sixth.")
  162.  
  163. ElseIf txtCarNotes.Text = "" Then
  164. MessageBox.Show("Enter Any Notes For The Car Into The Last Field.")
  165. End If
  166. End Sub
  167.  
  168. Private Sub btnDelete_Click(sender As Object, e As EventArgs) Handles btnDelete.Click
  169.  
  170. If MessageBox.Show("Do you really want to Delete this record?",
  171. "Delete", MessageBoxButtons.YesNo,
  172. MessageBoxIcon.Warning) = Windows.Forms.DialogResult.No Then
  173.  
  174. MsgBox("Operation Canceled")
  175. Exit Sub
  176.  
  177. End If
  178.  
  179. Dim cb As New OleDb.OleDbCommandBuilder(da)
  180.  
  181. ds.Tables("AddressBook").Rows(inc).Delete()
  182. MaxRows = MaxRows - 1
  183.  
  184. inc = 0
  185. da.Update(ds, "AddressBook")
  186. NavigateRecords()
  187. End Sub
  188.  
  189. Private Sub btnClear_Click(sender As Object, e As EventArgs) Handles btnClear.Click
  190.  
  191. btnCommit.Enabled = False
  192. btnAddNew.Enabled = True
  193. btnUpdate.Enabled = True
  194. btnDelete.Enabled = True
  195.  
  196. inc = 0
  197. NavigateRecords()
  198.  
  199. End Sub
  200. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement