HussAb
Wed Oct 29 19:21:29 CST 2003
Hi Sabine,
The following code should accomplish creating a subset table that has 2 columns out of 11 and all the rows:
Dim da1 As SqlDataAdapter = New SqlDataAdapter("select * from Customers", cn)
da1.Fill(ds, "customers")
Dim dtSubset As DataTable
dtSubset = ds.Tables("Customers").Copy 'Copy all the rows and columns
Dim count As Integer = dtSubset.Columns.Count
Dim i As Integer
For i = count To 3 Step -1
Dim dc As DataColumn = dtSubset.Columns(i - 1)
dtSubset.Columns.Remove(dc) 'Delete all the columns except the first 2 columns
Next i
DataGrid1.DataSource = dtSubset
The Remove method has an oveload that accepts a Column Name as an argument so you may specify a column name instead of a DataColumn object.
I hope this helps!
Thanks,
Hussein Abuthuraya
Microsoft Developer Support
This posting is provided "AS IS" with no warranties, and confers no rights.
Are you secure? For information about the Microsoft Strategic Technology Protection Program and to order your FREE Security Tool Kit, please visit
http://www.microsoft.com/security.