By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,825 Members | 1,281 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,825 IT Pros & Developers. It's quick & easy.

sub-selecting a DataTable?

P: n/a
Here's an example:

Dim dsMyData As DataSet
dsMyData = CallWebService(Param1,Param2)
Dim dtUsersTable As DataTable = dsMyData.Tables("Users")

I have a Web service that fills dsMyData with a couple tables.
My question is, from dsMyData.Tables("Users"), which contains all
users, how can I create another datatable that only returns for
UserID=1?

thanks...

Nov 19 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
> Dim dsMyData As DataSet
dsMyData = CallWebService(Param1,Param2)
Dim dtUsersTable As DataTable = dsMyData.Tables("Users")

I have a Web service that fills dsMyData with a couple tables.
My question is, from dsMyData.Tables("Users"), which contains all
users, how can I create another datatable that only returns for
UserID=1?


This may not be the easiest way, but it should work:

'line below copies structure of Users table to NewUsers table
Dim newUserTable As DataTable = dsMyData.tables("Users").Clone

'line below renames the cloned table as to avoid naming conflicts
newUsersTable.tableName = "NewUsers"

'selects users with userid=1 and imports into NewUsers table
For Each dr As DataRow In dsMyData.tables("Users").Select("UserID=1")
newUsersTable.ImportRow(dr)
Next

' adds the newUsers table to the dataset
dsMyData.Tables.Add(newUsesTable)
Hope it helps.
Jeppe Jespersen
Nov 19 '05 #2

P: n/a
Jeppe,

That did help.
Thank you very much.

Eych

Nov 19 '05 #3

P: n/a
> That did help.
Thank you very much.


No propblemo. :-)

Jeppe
Nov 19 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.