2012-04-19 68 views
2

我正在創建一個預約系統,我想這樣做,當用戶選擇日曆上的下拉框將填充可用的時間。除了操作員

下面是代碼我有...

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 

這是我得到的錯誤...

無法投類型的對象System.Data.Linq.DataQuery 1[System.TimeSpan]' to type 'System.Collections.Generic.IEnumerable 1 [VB $ AnonymousType_1`1 [System.TimeSpan]」。

從我的一般知識,我知道我將需要一個時間跨度.parse的地方,我已經玩過東西,但似乎無法解決它,任何人都可以幫忙嗎?

謝謝, Cora。

回答

3

我想你的意思是這樣的:

Dim times = From s In db.Apps 
      Where s.Date = Calendar1.SelectedDate 
      Select s.StartTime 

我想你可能已經向後得到了Except。你的意思是?

Dim leftover = allslots.Except(times) 
+0

我沒有,但它在下拉框中仍然沒有顯示任何東西,沒有錯誤只是空白:/ – Cora 2012-04-19 16:32:06

+0

我改變了下拉框從dropdownlist1至次,獲得了這個錯誤... 「數據源」不是'System.Linq.IQueryable(Of System.TimeSpan)'的成員。 – Cora 2012-04-19 16:34:55

+0

就是這樣!謝謝! – Cora 2012-04-19 16:36:50