【问题标题】:Except Operator运营商除外
【发布时间】:2012-04-19 16:18:09
【问题描述】:

我正在创建一个预订系统,我想这样当用户在日历上选择一个日期时,下拉框将填充可用的时间。

下面是我的代码...

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.DataQuery1[System.TimeSpan]' to type 'System.Collections.Generic.IEnumerable1[VB$AnonymousType_1`1[System.TimeSpan]]”的对象。

根据我的一般知识,我知道我需要在某个地方进行时间跨度解析,我玩过一些东西,但似乎无法解决,有人可以帮忙吗?

谢谢, 科拉。

【问题讨论】:

    标签: vb.net linq except


    【解决方案1】:

    我认为你的意思是:

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

    我认为您可能已经将Except 倒退了。你是这个意思吗?

    Dim leftover = allslots.Except(times)
    

    【讨论】:

    • 我做了,但下拉框中仍然没有显示任何内容,没有错误只是空白:/
    • 我将下拉框从 dropdownlist1 更改为 times 并收到此错误...“DataSource”不是“System.Linq.IQueryable(Of System.TimeSpan)”的成员。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-02-12
    • 1970-01-01
    • 2013-08-15
    • 2011-05-16
    • 2018-06-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多