q; merger two dataset

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello,
Is it possible to merge two datasets which have three tables in each of
them? I am musing .Net 2.0 if this makes anything easier.
Any sample code will be greatly appreciated.
Thanks,
 
The easy way is with the dataset designer. If you want to do it
programmatically, try:

Dim connString As String = My.Settings.ProjectConnection
Dim ds As New DataSet

Using cnn As New SqlClient.SqlConnection(connString)
cnn.Open()
Using cmd As New SqlClient.SqlCommand("mySP", cnn)
cmd.CommandType = CommandType.StoredProcedure
cmd.Parameters.AddWithValue("@myParam", myValue)
Using da As New SqlClient.SqlDataAdapter(cmd)
da.TableMappings.Add("Table", "MyDatasetName1")
da.TableMappings.Add("Table1", "MyDatasetName2")
da.TableMappings.Add("Table2", "MyDatasetName3")
da.Fill(ds)
End Using
End Using
cnn.Close()
End Using

In the stored procedure just write some SQL
SELECT * FROM MyTableName1
SELECT * FROM MyTableName2
SELECT * FROM MyTableName3

It will work equally well with multiple dynamic SQL statements.
 
Hello Larry,
Thanks you very much for your reply. This fills the dataset, I need to merge
it with another dataset with the same schema, will that work with three
tables?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top