vb.net Linq 筛选(像 select distinct) DateTable 日期数据中的年份

时间:2021-01-23 18:06:12
    Private Sub initDDLByYear(ByVal dt As DataTable)

        ddlByYear.Items.Clear()
ddlByYear.Items.Add(New ListItem(GetGlobalResourceObject("Resource1", "All"), "")) If Not dt Is Nothing Then
Dim years = (From r In dt.AsEnumerable
Select DateTime.Parse(r("create_date").ToString()).ToString("yyyy")).Distinct For Each y In years
ddlByYear.Items.Add(New ListItem(y.ToString, y.ToString))
Next End If End Sub