Parse table from one dataset and create new dataset using this table

  • Thread starter Thread starter moondaddy
  • Start date Start date
M

moondaddy

I have a strongly typed dataset with multiple tables and I want to take one
of the tables and create a new dataset using this one table and its data.
This is because I'm returning all of these tables via one webservice call,
but in the end, I need to have this one table separate from the others. The
other tables are used for support data to populate lists and combo boxes.
Ocationionaly the one table will have its data updated and if its part of
the same dataset as the other tables, when I update the data it causes all
the controls bound to the other tables to repopulate or refresh. Is there
an elegant way to simply create a new dataset and import a table and its
data from another dataset? I'm using strongly typed datasets (even for the
target dataset in this scenario) and vs2003 / vb.net.

Thanks.
 
There's a very elegant way, using the Merge method:

'-- Begin sample code
Dim oCn As New
SqlConnection("server=(local);database=northwind;integrated security=sspi;")
Dim oDa As New SqlDataAdapter("SELECT * FROM Customers", oCn)
Dim oDs1 As New DataSet
Dim oDs2 As New DataSet


oDa.Fill(oDs1, "Customers")
'fill oDs1 with whatever else you want, and then:

'just copy the table to the new dataset:
oDs2.Merge(oDs1.Tables("Customers"))
'-- End sample code

Hope this helps!

Steven Bras, MCSD
Microsoft Developer Support/Data Access Technologies

This posting is provided "AS IS" with no warranties, and confers no rights.

Microsoft Security Announcement: Have you installed the patch for Microsoft
Security Bulletin MS03-026?  If not Microsoft strongly advises you to
review the information at the following link regarding Microsoft Security
Bulletin MS03-026
http://www.microsoft.com/security/security_bulletins/ms03-026.asp and/or to
visit Windows Update at http://windowsupdate.microsoft.com to install the
patch. Running the SCAN program from the Windows Update site will help to
insure you are current with all security patches, not just MS03-026.
 
Back
Top