【问题标题】:how to select specific columns from a data table in vb.net?如何从 vb.net 中的数据表中选择特定列?
【发布时间】:2014-03-08 20:16:00
【问题描述】:

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

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 

【问题讨论】:

    标签: asp.net vb.net datatable datarow


    【解决方案1】:
    Dim view As New DataView(MyDataTable)
    Dim distinctValues As DataTable = view.ToTable(True, "ColumnA")
    

    【讨论】:

      【解决方案2】:

      这样试试

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

      【讨论】:

      • 如果我想选择多个列并按特定列过滤,我应该怎么做?
      猜你喜欢
      • 1970-01-01
      • 2020-10-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-03-20
      • 1970-01-01
      • 2022-07-08
      • 1970-01-01
      相关资源
      最近更新 更多