Basically what I need to do is to insert into table Reservation a vehicleID, startDate and endDate.
I can do that fine but I’d like to validate it so that it cannot be inserted for that vehicleID if the current date is <= endDate as currently I can just keep adding to the Reservation table on the same vehicleID
This is just the simple insert SQL statement.
strInsert = String.Format("Insert into Reservation (VehicleID, startDate, enddate) VALUES ('{0}','{1}','{2}')", vID, now, now5)
Regards.
How about not attempting an insert if today’s date is less than the enddate you are inserting?
UPDATE
If you are implementing this all in SQL, then I recommend using a stored procedure, but in either case the logic is the same. Check to see if any reservations exist that overlap today and if they do, throw an exception from SQL.
Note that
GETDATE()is not quite the right value to use since it returns the current timestamp, but without know how the values are stored, it is used as an approximation and can be cleaned up later.To call this stored procedure from your code: