Reputation: 43
I am creating a booking system, I want to make it so when the user selects a date on the calander the dropdown box will become populated with the times which are available.
Below is the code I have...
Protected Sub Calendar1_SelectionChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Calendar1.SelectionChanged
Label1.Text = Calendar1.SelectedDate
Dim db As New DataClasses2DataContext
Dim times = From s In db.Apps Where s.Date = Calendar1.SelectedDate Select New With {s.StartTime}
Dim allslots = From c In db.Slots Select c.StartTime
Dim leftover = times.Except(allslots)
DropDownList1.DataSource = leftover
DropDownList1.DataBind()
End Sub
This is the error I am getting...
Unable to cast object of type 'System.Data.Linq.DataQuery1[System.TimeSpan]' to type 'System.Collections.Generic.IEnumerable
1[VB$AnonymousType_1`1[System.TimeSpan]]'.
From my general knowledge I know that I am going to need a timespan.parse somewhere, I have had a play around with things but cant seem to work it out, can anyone help?
thanks, Cora.
Upvotes: 2
Views: 3558
Reputation: 44316
I think you meant this:
Dim times = From s In db.Apps
Where s.Date = Calendar1.SelectedDate
Select s.StartTime
I think you may have gotten the Except
backwards. Did you mean this?
Dim leftover = allslots.Except(times)
Upvotes: 3