Okay, so i'm working on my final project for VB.net II. I'm created a project for a hotel stay situation and I have everything working perfectly. I need help however on adding something to it.
I have it to where either your a new guest/customer or a returning. If your new, when you submit the form, it adds the customers information to the database. My Access database has 2 tables: Customer and CustomerStays.
Now, the primary key in both of them is a field called: CustomerID and they have a relationship tied together in the database itself.
Fields of the Customer table include: CustomerID, CustomerName, CustomerAddress, CustomerZipcode, and CustomerTagNumber
Fields of the CustomerStays table include: CustomerID, CustomerDateIn, CustomerDateOut, and TotalDays
Here is an image of my main form:
When they click total for stay, here is the code that goes through with it
Private Sub TotalForStayBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TotalForStayBtn.Click
ErrorChecking() 'Sub routine that checks for errors
If YourGood = True Then 'Only good if you pass the error check
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''ADDING CUSTOMER INFORMATION TO THE DATABASE''''''''''''''''
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
If ExistingCustomer = False Then
Try
myconnection.Open()
Dim str As String
str = "SELECT * FROM Customer WHERE CustomerTagNumber='" & CustomerTagNumbertxt.Text & "'"
Dim cmd As OleDbCommand = New OleDbCommand(str, myconnection)
dr = cmd.ExecuteReader
If dr.Read Then
If MsgBox("That license plate tag number already exists. Are you an existing customer?", MsgBoxStyle.YesNo) = MsgBoxResult.Yes Then
ReturningCustomerLookup.Show()
Me.Close()
ElseIf MsgBoxResult.No Then
MessageBox.Show("Please re-enter your own license plate tag number and verify that it is entered correctly.")
End If
Else
str = "INSERT INTO Customer (CustomerName, CustomerAddress, CustomerZip, CustomerTagNumber)" _
& " VALUES ('" & CustomerNametxt.Text & "','" _
& CustomerAddresstxt.Text & "','" _
& CustomerZipCodetxt.Text & "','" _
& CustomerTagNumbertxt.Text & "')"
cmd = New OleDbCommand(str, myconnection)
cmd.ExecuteNonQuery()
MessageBox.Show("Your information has been successfully added to the database", "Successful")
'''''''CALCULATING THE TOTAL'''''''
CalculateTotal()
'''''END CALCULATING THE TOTAL'''''
'''''''ADDING DATES INFO TO DATABASE'''''''
**CustomerStaysInsertion()**
'''''END ADDING DATES INFO TO DATABASE'''''
End If
Catch ex As Exception
MessageBox.Show("There was an error inserting your information into the database" _
& vbCrLf & vbCrLf & "Original Error: " & ex.ToString, _
"Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Finally
myconnection.Close()
End Try
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''END ADDING CUSTOMER INFORMATION TO THE DATABASE''''''''''''''
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Else
'''''''CALCULATING THE TOTAL'''''''
CalculateTotal()
'''''END CALCULATING THE TOTAL'''''
End If
End If
End Sub
Now my problem is the CustomerStays information. It runs the subroutine and what I want it to do is use the information of the customer to grab the CustomerID in the Customer table and place that AS CustomerID in the CustomerStays table along with the date that they check in and check out and the total number of days staying.
Basically, I need it to insert all of that information with the CustomerID that belongs to the customer that is currently staying at the hotel.
Additional info:
Names for some controls:
Date in - DateInPicker
Date out - DateOutPicker
Total Days - TotalDayslbl