Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Does anybody know how you can merge data from an Untyped Dataset into a specific table of a Strongly Typed Dataset?

 

Check out the following function:

<code>

 

 

Public Function GetCustomerss() As dstCustomers

 

Try

 

Dim dst As New DataSet

 

Dim tablenames() As String = {"Customers"}

 

SqlHelper.FillDataset(SqlDataAdapter1.SelectCommand, dst, tablenames)

 

DstCustomers1.Merge(dst)

 

Catch ex As Exception

 

Throw (ex)

 

Finally

 

SqlDataAdapter1.Dispose()

 

SqlConnection1.Close()

 

End Try

 

Return DstCustomers1

 

End Function

</code>

 

Suppose that dataset "DstCustomers1" has two tables in it (Customers and Orders). When you perform the following code,

<code>

 

 

DstCustomers1.Merge(dst)

</code>

if 'DstCustomers1' has only one table, it will perform the merge with no problem. However, how can you specifically merge the contents of the Untyped dataset into a specific table of DstCustomers1 (like into the Customers or Orders table)?

Thanks,

 

Bill Yeager (MCP, BCIP)

Microsoft Certified Professional

Brainbench Certified Internet Professional, .Net Programmer, Computer Programmer

YeagerTech Consulting, Inc.

Posted

Possible solution

 

The only thing I can think of that would accomplish this is the following code:

 

<code>

Dim dr As DataRow

For Each dr In dst.Tables(0).Rows

DstCustomers1.Customers.ImportRow(dr)

Next

</code>

 

If anyone has anything more efficient, just let me know....

Thanks,

 

Bill Yeager (MCP, BCIP)

Microsoft Certified Professional

Brainbench Certified Internet Professional, .Net Programmer, Computer Programmer

YeagerTech Consulting, Inc.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...