2012-03-14 5 views
1

DataTableの「結果」があり、x個の異なる値(都市)を取得してDataTableに戻したいのですが、以下のコードでエラーが表示されますDistinct値を取得してDataTableに変換する

Dim query = (From x In results.AsEnumerable() 
         Select (x.Field(Of String)("City"))).Distinct().CopyToDataTable() 

ので、私が何をしたい私はそれを得ることができます明確な都市のレコードですが、私が午前問題はDatableに戻ってそれを変換しています。

編集:私は「どこで」この文で使用しています

、それは表(正常に動作します)にではなく、上で変換しない

Dim results = (From myRow In ds.Tables(1).AsEnumerable() 
      Where (myRow.Field(Of String)("xxxx") = xxxx) 
          Select myRow).Distinct().CopyToDataTable() 

答えて

0

これは、あなたが探していた例を「選択」?

' Bind the System.Windows.Forms.DataGridView object 
' to the System.Windows.Forms.BindingSource object. 
dataGridView.DataSource = bindingSource 

' Fill the DataSet. 
Dim ds As New DataSet() 
ds.Locale = CultureInfo.InvariantCulture 
' See the FillDataSet method in the Loading Data Into a DataSet topic. 
FillDataSet(ds) 

Dim orders As DataTable = ds.Tables("SalesOrderHeader") 

' Query the SalesOrderHeader table for orders placed 
' after August 8, 2001. 
Dim query = _ 
    From order In orders.AsEnumerable() _ 
    Where order.Field(Of DateTime)("OrderDate") > New DateTime(2001, 8, 1) _ 
    Select order 

' Create a table from the query. 
Dim boundTable As DataTable = query.CopyToDataTable() 

' Bind the table to a System.Windows.Forms.BindingSource object, 
' which acts as a proxy for a System.Windows.Forms.DataGridView object. 
bindingSource.DataSource = boundTable 

http://msdn.microsoft.com/en-us/library/bb386921.aspx