Home > DeveloperSection > Forums > how to select specific columns from a data table in vb.net?
sandy taylor
sandy taylor

Total Post:46

Points:324
Posted on    December-05-2014 10:19 PM

 .NET VB.Net 
Ratings:


 2 Reply(s)
 886  View(s)
Rate this:

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



Ankit Singh

Total Post:341

Points:2389
Posted on    December-06-2014 4:49 AM

Dim view As New DataView(MyDataTable)

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


Tanuj Kumar

Total Post:134

Points:940
Posted on    December-06-2014 5:45 AM

Try like This

 

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

"columnname1", "name2","...","..")


Don't want to miss updates? Please click the below button!

Follow MindStick