本帖最后由 rockage 于 2017-1-14 19:45 编辑
LINQ,语言集成查询(Language Integrated Query)是一组用于c#和Visual Basic语言的扩展。它允许编写C#或者Visual Basic代码以查询数据库相同的方式操作内存数据。
这是最最简单的Linq范例, 数组反向排序。
这是Linq和Datatable的结合,可以使本地数据库也支持多列排序。
LINQ,语言集成查询(Language Integrated Query)是一组用于c#和Visual Basic语言的扩展。它允许编写C#或者Visual Basic代码以查询数据库相同的方式操作内存数据。
Dim arr() As Integer = {0, 1, 2, 3, 4, 5}
Dim tempi = From p In arr
Order By p Descending
Select p
Dim i As Integer
For i = 0 To tempi.Count - 1
ListBox1.Items.Add(tempi(i))
Next这是最最简单的Linq范例, 数组反向排序。
Dim table As New DataTable
table.Columns.Add("A", GetType(Integer))
table.Columns.Add("B", GetType(Integer))
table.Columns.Add("C", GetType(Integer))
table.Rows.Add(1, 1, 3)
table.Rows.Add(2, 2, 3)
table.Rows.Add(2, 3, 3)
table.Rows.Add(2, 4, 3)
table.Rows.Add(2, 5, 3)
table.Rows.Add(3, 6, 3)
'linq进行多列order by的示例
Dim temp = From p In table.AsEnumerable
Order By p("A") Descending, p("B") Ascending
Select p
Dim table2 As DataTable
table2 = table.Clone
dg1.DataSource = table2这是Linq和Datatable的结合,可以使本地数据库也支持多列排序。