本文整理汇总了VB.NET中System.Data.DataTable.Select方法的典型用法代码示例。如果您正苦于以下问题:VB.NET DataTable.Select方法的具体用法?VB.NET DataTable.Select怎么用?VB.NET DataTable.Select使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Data.DataTable
的用法示例。
在下文中一共展示了DataTable.Select方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的VB.NET代码示例。
示例1: GetRows
Private Sub GetRows()
' Get the DataTable of a DataSet.
Dim table As DataTable = DataSet1.Tables("Suppliers")
Dim rows() As DataRow = table.Select()
Dim i As Integer
' Print the value one column of each DataRow.
For i = 0 to rows.GetUpperBound(0)
Console.WriteLine(rows(i)("CompanyName"))
Next i
End Sub
示例2: GetRowsByFilter
Private Sub GetRowsByFilter()
Dim table As DataTable = DataSet1.Tables("Orders")
' Presuming the DataTable has a column named Date.
Dim expression As String
expression = "Date > #1/1/00#"
Dim foundRows() As DataRow
' Use the Select method to find all rows matching the filter.
foundRows = table.Select(expression)
Dim i As Integer
' Print column 0 of each returned row.
For i = 0 to foundRows.GetUpperBound(0)
Console.WriteLine(foundRows(i)(0))
Next i
End Sub
示例3: Main
' 导入命名空间
Imports System.Data
Public Class A
Public Shared Sub Main()
Dim table As New DataTable("Orders")
table.Columns.Add("OrderID", GetType(Int32))
table.Columns.Add("OrderQuantity", GetType(Int32))
table.Columns.Add("CompanyName", GetType(String))
table.Columns.Add("Date", GetType(DateTime))
Dim newRow As DataRow = table.NewRow()
newRow("OrderID") = 1
newRow("OrderQuantity") = 3
newRow("CompanyName") = "NewCompanyName"
newRow("Date") = "1979, 1, 31"
' Add the row to the rows collection.
table.Rows.Add(newRow)
Dim newRow2 As DataRow = table.NewRow()
newRow2("OrderID") = 2
newRow2("OrderQuantity") = 2
newRow2("CompanyName") = "NewCompanyName1"
table.Rows.Add(newRow2)
Dim newRow3 As DataRow = table.NewRow()
newRow3("OrderID") = 3
newRow3("OrderQuantity") = 2
newRow3("CompanyName") = "NewCompanyName2"
table.Rows.Add(newRow3)
' Presuming the DataTable has a column named Date.
Dim expression As String = "Date = '1/31/1979' or OrderID = 2"
' Dim expression As String = "OrderQuantity = 2 and OrderID = 2"
' Sort descending by column named CompanyName.
Dim sortOrder As String = "CompanyName ASC"
Dim foundRows As DataRow()
' Use the Select method to find all rows matching the filter.
foundRows = table.[Select](expression, sortOrder)
' Print column 0 of each returned row.
For i As Integer = 0 To foundRows.Length - 1
Console.WriteLine(foundRows(i)(2))
Next
End Sub
End Class
示例4: GetRowsByFilter
Private Sub GetRowsByFilter()
Dim customerTable As New DataTable("Customers")
' Add columns
customerTable.Columns.Add("id", GetType(Integer))
customerTable.Columns.Add("name", GetType(String))
' Set PrimaryKey
customerTable.Columns("id").Unique = True
customerTable.PrimaryKey = New DataColumn() _
{customerTable.Columns("id")}
' add ten rows
Dim id As Integer
For id = 1 To 10
customerTable.Rows.Add( _
New Object() {id, String.Format("customer{0}", id)})
Next id
customerTable.AcceptChanges()
' add another ten rows
For id = 11 To 20
customerTable.Rows.Add( _
New Object() {id, String.Format("customer{0}", id)})
Next id
Dim expression As String
Dim sortOrder As String
expression = "id > 5"
' Sort descending by CompanyName column.
sortOrder = "name DESC"
' Use the Select method to find all rows matching the filter.
Dim foundRows As DataRow() = _
customerTable.Select(expression, sortOrder, _
DataViewRowState.Added)
PrintRows(foundRows, "filtered rows")
foundRows = customerTable.Select()
PrintRows(foundRows, "all rows")
End Sub
Private Sub PrintRows(ByVal rows() As DataRow, ByVal label As String)
Console.WriteLine("\n{0}", label)
If rows.Length <= 0 Then
Console.WriteLine("no rows found")
Exit Sub
End If
Dim row As DataRow
Dim column As DataColumn
For Each row In rows
For Each column In row.Table.Columns
Console.Write("\table {0}", row(column))
Next column
Console.WriteLine()
Next row
End Sub