如何从 vb.net 中的数据表中选择特定列?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21695167/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 16:44:54 来源:igfitidea点击:
how to select specific columns from a data table in vb.net?
提问by sona
I have a data table from which i am filtering data based on condition,but how to display specific columns only from the data table?
我有一个数据表,我正在根据条件从中过滤数据,但是如何仅显示数据表中的特定列?
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
采纳答案by Satinder singh
Dim view As New DataView(MyDataTable)
Dim distinctValues As DataTable = view.ToTable(True, "ColumnA")
回答by Sathish
Try like This
像这样尝试
TempDt =New DataView(Rows.CopyToDataTable()).ToTable(False,
"columnname1", "name2","...","..")

