如何从vb.net中的数据表中选择特定列?

时间:2014-02-11 06:56:50

标签: asp.net vb.net datatable datarow

我有一个数据表,我根据条件从中过滤数据,但是如何仅显示数据表中的特定列?

Dim Dt As New DataTable
                Dim SQlDa As SqlDataAdapter = New SqlDataAdapter(SqlCmd)
                SQlDa.Fill(TrackingDt)
                Dim Rows() As DataRow = Dt.Select("State = " + "'" + State + "'")
                Dim TempDt As New DataTable
                If Rows.Length > -1 Then
                    TempDt = Rows.CopyToDataTable()
                End If


                Return TempDt 

2 个答案:

答案 0 :(得分:1)

Dim view As New DataView(MyDataTable)
Dim distinctValues As DataTable = view.ToTable(True, "ColumnA")

答案 1 :(得分:0)

试试这个

TempDt =New DataView(Rows.CopyToDataTable()).ToTable(False, 
"columnname1", "name2","...","..")