Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I have a dataset that holds data from a sql command from server1. This dataset holds some stats on users and has a column called dbid. I'd like to use another database and go against server2 to bring back the dbid and the dbname. The result I want is to be able to use the stats that are on server1 and the dbname on server2 joing the two tables together in code. I don't want to use a linked server to get this info, I"d like to have vb do the join in a dataset. Can someone help me out. I've been doing the research and think I need to use dataTableMapping but can't get my mind around it. So the dataset.table that I have are one called stats and one called database. Any help would be great.

 

thanks

shannon

JvCoach23

VB.Net newbie

MS Sql Vet

  • Administrators
Posted

Probably the best way would to be load the data into two seperate DataTables within the same DataSet. You could then create a DataRelation and add this to the DataSet's Relations collection.

This would allow you to write code which could then navigate the relationship or alternatively the grid control for windows forms will display the relationship as well.

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

  • Administrators
Posted

Bit rough and ready but should give you the idea. In practice I would be more inclined to use stored procedures rather than hard coding the SELECT.... statements.

You may also want to consider using a strongly typed DataSet rather than how I've done it below....

'Just create 2 connections (1 per server)
Dim conn As New SqlConnection("Initial Catalog=Northwind;Integrated Security=true;Data Source=(local)")
'assign the correct connection to each data adapter
Dim daCustomers As New SqlDataAdapter("SELECT * FROM Customers", conn)
Dim daOrders As New SqlDataAdapter("SELECT * FROM Orders", conn)

Dim ds As New DataSet
daCustomers.Fill(ds, "Customers")
daOrders.Fill(ds, "Orders")

Dim dr As New DataRelation("CustomerOrders",     ds.Tables("Customers").Columns("CustomerID"), ds.Tables("Orders").Columns("CustomerID"))
ds.Relations.Add(dr)

DataGrid1.DataSource = ds.Tables("Customers")

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Posted

thanks for the help so far.. hope your still willing to help.

 

I see how the relation is made.. now to have the dataset return a combination of the two tables.. do you have to use mapping.. got any examples of that. I"m going to play around with the strongly typed..never used those before.. still learning. perhaps they are the answer.. anyway.. if you have input your willing to share. that woudl be great

 

thanks

shannon

JvCoach23

VB.Net newbie

MS Sql Vet

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...