Guest User

Untitled

a guest
Jan 6th, 2018
374
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.49 KB | None | 0 0
  1. Dim cn As New OleDbConnection
  2. Dim cm As New OleDbCommand
  3.  
  4. Try
  5. With cn
  6. .ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:Assessment of the CKC Library SystemDatabase.accdb"
  7. .Open()
  8. End With
  9.  
  10. With cm
  11. .Connection = cn
  12. .CommandType = CommandType.Text
  13. .CommandText = "INSERT INTO [Books] ([ISBN],[BookTitle],[Author],[Category],[Foreword],[YearPublished], [Quantity]) VALUES ('" & txtISBN.Text & "', '" & txtBookTitle.Text & "', '" & txtAuthor.Text & "', '" & cboCategory.Text & "', '" & txtForeword.Text & "', '" & cboYearPublished.Text & "', '" & cboQuantity.Text & "')"
  14.  
  15. .Parameters.Add(New System.Data.OleDb.OleDbParameter("@ISBN", System.Data.OleDb.OleDbType.VarChar, 30, Me.txtISBN.Text))
  16. .Parameters.Add(New System.Data.OleDb.OleDbParameter("@BookTitle", System.Data.OleDb.OleDbType.VarChar, 255, Me.txtBookTitle.Text))
  17. .Parameters.Add(New System.Data.OleDb.OleDbParameter("@Author", System.Data.OleDb.OleDbType.VarChar, 255, Me.txtAuthor.Text))
  18. .Parameters.Add(New System.Data.OleDb.OleDbParameter("@Category", System.Data.OleDb.OleDbType.VarChar, 255, Me.cboCategory.Text))
  19. .Parameters.Add(New System.Data.OleDb.OleDbParameter("@Foreword", System.Data.OleDb.OleDbType.VarChar, 255, Me.txtForeword.Text))
  20. .Parameters.Add(New System.Data.OleDb.OleDbParameter("@YearPublished", System.Data.OleDb.OleDbType.VarChar, 255, Me.cboYearPublished.Text))
  21. .Parameters.Add(New System.Data.OleDb.OleDbParameter("@Quantity", System.Data.OleDb.OleDbType.VarChar, 255, Me.cboQuantity.Text))
  22.  
  23. 'RUNS THE COMMAND
  24. cm.Parameters("@ISBN").Value = Me.txtISBN.Text
  25. cm.Parameters("@BookTitle").Value = Me.txtBookTitle.Text
  26. cm.Parameters("@Author").Value = Me.txtAuthor.Text
  27. cm.Parameters("@Category").Value = Me.cboCategory.Text
  28. cm.Parameters("@Foreword").Value = Me.txtForeword.Text
  29. cm.Parameters("@YearPublished").Value = Me.cboYearPublished.Text
  30. cm.Parameters("@Quantity").Value = Me.cboQuantity.Text
  31.  
  32.  
  33.  
  34.  
  35. cm.ExecuteNonQuery()
  36. MsgBox("Book added.", MsgBoxStyle.Information, "Saved Successfully!")
  37. Me.txtISBN.Text = ""
  38. Me.txtBookTitle.Text = ""
  39. Me.txtAuthor.Text = ""
  40. Me.txtForeword.Text = ""
  41. cboCategory.SelectedIndex = -1
  42. cboQuantity.SelectedIndex = -1
  43. cboYearPublished.SelectedIndex = -1
  44.  
  45. Exit Sub
  46. End With
  47.  
  48. Catch ex As Exception
  49. MsgBox("Please fill all the details needed and be sure that the ISBN doesn't have any letters. ", MsgBoxStyle.Exclamation, "Error")
  50.  
  51.  
  52. End Try
  53. End Sub
  54.  
  55. Private Sub btnCancel_Click(sender As Object, e As EventArgs) Handles btnCancel.Click
  56. Hide()
  57. End Sub
  58.  
  59. Private Sub BooksBindingNavigatorSaveItem_Click(sender As Object, e As EventArgs)
  60. Me.Validate()
  61. Me.BooksBindingSource.EndEdit()
  62. Me.TableAdapterManager.UpdateAll(Me.DatabaseDataSet)
  63.  
  64. End Sub
  65.  
  66. Private Sub frmSearchUpdateBooks_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  67. 'TODO: This line of code loads data into the 'DatabaseDataSet.Books' table. You can move, or remove it, as needed.
  68. Me.BooksTableAdapter.Fill(Me.DatabaseDataSet.Books)
  69.  
  70. End Sub
  71.  
  72. Private Sub btnSave_Click(sender As Object, e As EventArgs) Handles btnSave.Click
  73. Try
  74. BooksBindingSource.EndEdit()
  75. BooksTableAdapter.Update(DatabaseDataSet)
  76. MsgBox("Successfully saved.", MsgBoxStyle.OkOnly, "Success!")
  77. DataGridView1.Refresh()
  78.  
  79. Catch ex As Exception
  80. MsgBox("Please fill all the information needed. If all informations are filled up, please re-check the ISBN as some book might have the same ISBN as you are entering.", MsgBoxStyle.OkOnly, "Error!")
  81. End Try
  82. End Sub
  83.  
  84. Private Sub btnDelete_Click(sender As Object, e As EventArgs) Handles btnDelete.Click
  85. BooksBindingSource.RemoveCurrent()
  86. BooksBindingSource.EndEdit()
  87. MsgBox("Item successfully deleted!", MsgBoxStyle.OkOnly, "Success!")
  88. End Sub
  89.  
  90. Private Sub btnUpdate_Click(sender As Object, e As EventArgs) Handles btnUpdate.Click
  91. Try
  92. Me.Validate()
  93. Me.BooksBindingSource.EndEdit()
  94. Me.BooksTableAdapter.Update(DatabaseDataSet)
  95. MsgBox("Updated Successfully!", MsgBoxStyle.OkOnly, "Update Successful!")
  96. Catch ex As Exception
  97. MsgBox(ex.Message)
  98. Finally
  99. Me.BooksTableAdapter.Fill(DatabaseDataSet.Books)
  100. End Try
  101. End Sub
Add Comment
Please, Sign In to add comment