is it possible to use filter expression to select some columns?
something like select a,b,c from table in sql
here is what i am trying to do
Dim rows() As DataRow = bookedorders.Select("a,b,c") 'select columns a b c only, i know its wrong
Dim zzz As DataTable = rows.CopyToDataTable
so is it possible to use the Datatable.Select to select columns and the use a condition like sql WHERE a=1
my linq try was
Dim q = From r In bookedorders.AsEnumerable Select r.Field(Of Integer)("a") And r.Field(Of String)("b") And r.Field(Of String)("c") And r.Field(Of Integer)("d")
For Each m In q
zzz.Rows.Add(m)
Next
which doesnt seem to work, it says that the number of items in array is longer than the datatable!
DataTable.Select allows you to specify a filter as a
String:You cannot specify columns to be extracted because that would break type structure, as it is expected to return same
DataRowas you originally had. If you were to return only specific columns, you would need anotherDataTableto contain them.Assuming this functionality existed, limiting number of returned columns is not practical, because you already have your
DataRows filled with data, unlikeselect a,b,c from table, where you can reduce network bandwidth and speed up query performance by specifying only certain columns to be extracted from a database.If you want to use LINQ, you can do it like this:
Note that you cannot use results of this query to directly
.Addrows to aDataTable, because returned enumeration is not of typeDataRow. If you need it badly, here is an implementation on MSDN.