好吧,我正在爲VB.net II的最終項目工作。我爲酒店住宿情況創建了一個項目,並且我的一切都很完美。然而,我需要幫助,添加一些東西。如何將某些值(包括從其他表中拉出的客戶ID)插入到單獨的表中
我已經把它交給了你的新客人/客戶或者回來的地方。如果您的新用戶在提交表單時將客戶信息添加到數據庫中。我的Access數據庫有兩個表格:客戶和客戶住所。
現在,它們中的主鍵都是一個字段,名爲:CustomerID並且它們在數據庫本身中有一個關係。
的Customer表領域包括:客戶ID,客戶名稱,CustomerAddress,CustomerZipcode,並CustomerTagNumber
的CustomerStays表領域包括:客戶ID, CustomerDateIn,CustomerDateOut,並TotalDays
這裏是我的主要形式的圖像:
當他們點擊逗留總,在這裏是通過與它
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
進入現在的代碼我的問題是CustomerStays信息。它運行子程序和我想要它做的是使用客戶的信息搶客戶ID在客戶表,並將作爲客戶ID在CustomerStays與他們檢查日期進行表入住和退房以及入住天數。
基本上,我需要它將所有這些信息與屬於當前入住酒店的客戶的CustomerID一起插入。
附加信息:
名稱對於某些控件:
日期在 - DateInPicker
日期出來 - DateOutPicker
總天數 - TotalDayslbl
是的,兩個表中的主鍵稱爲CustomerID。他們隨時待命,他們的客戶ID保持不變,因爲如果他們輸入相同的信息,程序就會將其作爲回頭客。他們的CustomerStays表用於跟蹤客人單獨入住酒店。同一位客人可以多次逗留,因此他們的每位客人的客戶ID都必須屬於一位客人。 – 2013-04-23 16:14:25
在這種情況下CustomerStays中的CustomerID稱爲[ForeignKey](http://en.wikipedia.org/wiki/Foreign_key)不是PrimaryKey – Steve 2013-04-23 16:24:54
在任何情況下,我需要從Customer表中獲取customerid以將其插入到其他信息中進入customerstays表的customerid。我怎麼做? – 2013-04-23 16:36:32