Can anyone help me please!!
I am just new to programming so this might sound rather trivial, but it has me stumped!
I have to search a database to see if a date is available for a booking to be made by the user. If the date they have chosen is already stored in the database a message must inform them that they can not have this date, else save their chosen date and other booking details into the database.
I have been able to connect to the DB and store details if the chosen date is not there but if the date is already there this error occurs and the application crashes:
An unhandled exception of type 'System.Data.OleDb.OleDbException' occurred in system.data.dll
This happens at the line which updates the adapter with the dataset. Here is a snippet of my code to see if anyone out there has a clue.
P.S. I have already tried a Try/Catch but this does not allow the user to then choose another date if their first date is in the DataBase.
'Sets a new row to be filled in the db
myRow = DsAllFields1.Bookings.NewBookingsRow
'sets a search of the database for the chosen date
Dim intRow As Integer
myConnection.Open()
DsAllFields1.Tables(0).DefaultView.Sort = "date"
intRow = DsAllFields1.Tables(0).DefaultView.Find("chosendate")
Debug.WriteLine(intRow)
If intRow < 0 Then
myRow("date") = chosendate
myRow("name") = OrgName
myRow("age") = orgAge
myRow("house number or name") = orgHouse
myRow("post code") = orgPostcode
myRow("phone number") = orgPhone
myRow("optionCode") = EventChoice
'fills the dataset with the user-input data
DsAllFields1.Bookings.Rows.Add(myRow)
'updates the adapter with the dataset items
Me.oleDABookinsAll.Update(DsAllFields1)
'here that the error occurs
MessageBox.Show("Your date has been accepted and this booking has now been confirmed and stored. Thank you " & OrgName & "", MessageBoxButtons.OK)
'closes the connection with the database
myConnection.Close()
Else
MessageBox.Show(OrgName & " We are sorry but this date is not available for booking. You must now choose another.", "DATE UNAVAILABLE")
End If
I am just new to programming so this might sound rather trivial, but it has me stumped!
I have to search a database to see if a date is available for a booking to be made by the user. If the date they have chosen is already stored in the database a message must inform them that they can not have this date, else save their chosen date and other booking details into the database.
I have been able to connect to the DB and store details if the chosen date is not there but if the date is already there this error occurs and the application crashes:
An unhandled exception of type 'System.Data.OleDb.OleDbException' occurred in system.data.dll
This happens at the line which updates the adapter with the dataset. Here is a snippet of my code to see if anyone out there has a clue.
P.S. I have already tried a Try/Catch but this does not allow the user to then choose another date if their first date is in the DataBase.
'Sets a new row to be filled in the db
myRow = DsAllFields1.Bookings.NewBookingsRow
'sets a search of the database for the chosen date
Dim intRow As Integer
myConnection.Open()
DsAllFields1.Tables(0).DefaultView.Sort = "date"
intRow = DsAllFields1.Tables(0).DefaultView.Find("chosendate")
Debug.WriteLine(intRow)
If intRow < 0 Then
myRow("date") = chosendate
myRow("name") = OrgName
myRow("age") = orgAge
myRow("house number or name") = orgHouse
myRow("post code") = orgPostcode
myRow("phone number") = orgPhone
myRow("optionCode") = EventChoice
'fills the dataset with the user-input data
DsAllFields1.Bookings.Rows.Add(myRow)
'updates the adapter with the dataset items
Me.oleDABookinsAll.Update(DsAllFields1)
MessageBox.Show("Your date has been accepted and this booking has now been confirmed and stored. Thank you " & OrgName & "", MessageBoxButtons.OK)
'closes the connection with the database
myConnection.Close()
Else
MessageBox.Show(OrgName & " We are sorry but this date is not available for booking. You must now choose another.", "DATE UNAVAILABLE")
End If