问题
Public Class RoomInfo
Dim ValTx As String
Dim ValNr As Integer
Private Sub cboRoomType_DropDown(sender As System.Object, e As System.EventArgs) Handles cboRoomType.DropDown
cboRoomType.Items.Clear()
qry = "select RoomType from tblRoomType"
cmd = New OleDb.OleDbCommand(qry, con)
dr = cmd.ExecuteReader
While dr.Read
cboRoomType.Items.Add(dr("RoomType"))
End While
End Sub
Private Sub cboRoomType_SelectValueChanged(sender As Object, e As System.EventArgs) Handles cboRoomType.SelectedValueChanged
ValTx = cboRoomType.Text
qry = "select RoomType from tblRoomType where RoomType = '" & ValTx & "'"
cmd = New OleDb.OleDbCommand(qry, con)
dr = cmd.ExecuteReader
If dr.Read Then
ValTx = dr("RoomType")
End If
End Sub
Private Sub btnNext_Click(sender As System.Object, e As System.EventArgs) Handles btnNext.Click
qry = "Insert into tblCheckIn (Guest_ID, GRoomType, GRoomNo, GRoomID, GRoomAmount, CheckInDate, Days, ChecOutDate) values ('" &
txtGuestID.Text & "','" &
ValTx &
txtRoomNo.Text & "','" &
txtRoomId.Text & "','" &
txtRAmount.Text & "','" &
dtpCheckIn.Value &
txtDays.Text & "','" &
dtpCheckOut.Value & "')"
cmd = New OleDb.OleDbCommand(qry, con)
dr = cmd.ExecuteReader()
MsgBox("Successfully added in the database")
End Sub
I dont know what the problem is here. I guess it's the combobox, the selected value in combo box should be added in database. What is the right correct value for that combobox? Can someone help me?
回答1:
It is telling you that you have specified a different number of column to insert into (8) than the number of values to insert (6). This is because you have concatenated 2 of the values into 2 field I believe, just count them and you will see what I mean.
来源:https://stackoverflow.com/questions/29058093/error-number-of-query-values-and-destination-fields-are-not-the-same