I just want to ask if where should i put the execute reader so that i can write a code that pops up a message when the function runs successfully. Here's the code.
xprovider = ("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & "C:\Users\Public\Downloads\dbInventoryManagementProgram.accdb")
xconString = xprovider
xmyConnection.ConnectionString = xconString
xmyConnection.Open()
Dim xstr As String
xstr = "Insert into tblReports([Item],[Brand],[Quantity],[Transaction_Type],[Transaction_Date]) Values (?,?,?,?,?)"
Dim xcmd As OleDb.OleDbCommand = New OleDb.OleDbCommand(xstr, xmyConnection)
'Dim xdr As OleDbDataReader = xcmd.ExecuteReader()
xcmd.Parameters.Add(New OleDb.OleDbParameter("Item", CType(txtboxItem.Text, String)))
xcmd.Parameters.Add(New OleDb.OleDbParameter("Brand", CType(txtboxBrand.Text, String)))
xcmd.Parameters.Add(New OleDb.OleDbParameter("Quantity", CType(txtboxQuantity.Text, String)))
xcmd.Parameters.Add(New OleDb.OleDbParameter("Transaction_Type", CType(txtboxTransactionType.Text, String)))
xcmd.Parameters.Add(New OleDb.OleDbParameter("Transaction_Date", CType(dtpTransactionDate.Text, String)))
Try
xcmd.ExecuteNonQuery()
xcmd.Dispose()
xmyConnection.Close()
txtboxTransactionType.Clear()
Catch ex As Exception
MsgBox("Error: " & ex.Message, MsgBoxStyle.Critical)
End Try
Try If txtboxItem.Text = "" Then MsgBox("Warning! Do not leave any fields empty. Please try again.", MsgBoxStyle.Critical) txtboxItem.Clear() txtboxBrand.Clear() txtboxQuantity.Clear() ElseIf txtboxBrand.Text = "" Then MsgBox("Warning! Do not leave any fields empty. Please try again.", MsgBoxStyle.Critical) txtboxItem.Clear() txtboxBrand.Clear() txtboxQuantity.Clear() ElseIf txtboxQuantity.Text = "" Then MsgBox("Warning! Do not leave any fields empty. Please try again.", MsgBoxStyle.Critical) txtboxItem.Clear() txtboxBrand.Clear() txtboxQuantity.Clear() ElseIf dtpTransactionDate.Text = "" Then MsgBox("Warning! Do not leave any fields empty. Please try again.", MsgBoxStyle.Critical) txtboxItem.Clear() txtboxBrand.Clear() txtboxQuantity.Clear() ElseIf xdr.HasRows Then MsgBox("Input success! Press ok to continue....", MsgBoxStyle.Information) txtboxItem.Clear() txtboxBrand.Clear() txtboxQuantity.Clear() Else MsgBox("Warning! There is some error detected. Please fill up the form correctly.", MsgBoxStyle.Critical) End If Catch ex As Exception MsgBox("Error: " & ex.Message, MsgBoxStyle.Critical) End Try
Using
block to ensure it's closed. You can put that in the Try too. Have everything in the Try. Let me create another answer with some changes to your entire post. – Michael Z.