私は次のものを持っています:
Dim dt As DataTable = ds.Tables(0)
Tables(0)には約20列あります。私はカップルだけを選ぶのが好きです。「PrID」はフィールドの1つです。
私は試した
Dim dt As DataTable = ds.Tables(0).Select("PrID")
成功せずに。何か案が?
私は次のものを持っています:
Dim dt As DataTable = ds.Tables(0)
Tables(0)には約20列あります。私はカップルだけを選ぶのが好きです。「PrID」はフィールドの1つです。
私は試した
Dim dt As DataTable = ds.Tables(0).Select("PrID")
成功せずに。何か案が?
1 つの方法は、厳密に型指定され、null 許容型をサポートするDataRow
拡張メソッドを使用することです。Field
For Each row As DataRow in ds.Tables(0).Rows
Dim PrID As Int32 = row.Field(Of Int32)("PrID")
Next
編集:DataTable
元の DataTable の列のサブセットを持つ別のものが必要な場合DataView
は、テーブルとそのToTable
メソッドを使用できます。
Dim displayView = New DataView(ds.Tables(0))
' if you're only interested in: PrID, Col2, Col3
Dim subset As DataTable = displayView.ToTable(false, "PrID", "Col2", "Col3")
を使用してPRID列を取得できます。
Dim dt As New DataTable
Dim columns As String() = "PrID".Split(",")
dt = ds.Tables(0).DefaultView.ToTable(String.Empty, False, columns)
'first create a new Dataview
Dim [Dataview] As New DataView
'here add the table to Dataview you want to filter its columns
[Dataview].Table = Ds.Tables(" here Write TableName ")
'here you can display selected Columns in Datatable
Dim [datatable] As DataTable = [Dataview].ToTable(False, "desired column Name ", "desired Column Name")
'here you can display selected Columns in DatagridView1
DataGridView1.DataSource = [Dataview].ToTable(False, "desired column Name ", "desired Column Name")