My Form 1 has a drop down list for user to select username, followed by a textbox to enter password. If correct password is entered, Form 2 will show.
Form 2 start from cbxCategory for category, then another cbxItem for item.
Then a button to click “Borrow”
Then it should insert.
This is my form 2_load codes:
Code:
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Form1.Hide()
'set the minimum date for loan date
dtpLoanDate.MinDate = DateAdd(DateInterval.Day, 0, Date.Today)
Dim conn As New OleDbConnection(connString)
Try
Dim comm_Category As New OleDbCommand("Select CategoryName from Category", conn)
conn.Open()
Dim da_item As New OleDbDataAdapter(comm_Category)
Dim da_category As New OleDbDataAdapter(comm_Category)
Dim ds As New DataSet
da_category.Fill(ds, "Category")
cbxCategory.DataSource = ds.Tables("Category")
cbxCategory.DisplayMember = "CategoryName"
cbxCategory.ValueMember = "CategoryName"
cbxCategory.SelectedIndex = -1
'Not sure if need these 3 lines below
Dim comm_Staff As New OleDbCommand("Select * from Staff", conn)
Form1.cbxStaff.DataSource = ds.Tables("Staff")
Form1.cbxStaff.ValueMember = "StaffID"
Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
conn.Close()
End Try
End Sub
My "borrow" button codes:
Code:
Private Sub btnBorrow_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBorrow.Click
Dim conn As New OleDbConnection(connString)
Try
Dim comm_loan As New OleDbCommand("Insert into loan(staffid, itemid,loandate,estreturndate)" & _
" values (@staffid, @itemid,@loandate,@estreturndate)", conn)
comm_loan.Parameters.AddWithValue("@staffid", Form1.cbxStaff.SelectedValue)
comm_loan.Parameters.AddWithValue("@itemid", cbxItem.SelectedValue)
comm_loan.Parameters.AddWithValue("@loandate", dtpLoanDate.Value)
comm_loan.Parameters.AddWithValue("@returndate", dtpReturnDate.Value)
conn.Open()
'The line below has run time error: Data type mismatch in criteria expression.
comm_loan.ExecuteNonQuery()
MessageBox.Show("Loan record created")
Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
conn.Close()
End Try
End Sub
I keep getting an error when I try to insert the record. What's wrong with my code?