q; merger two dataset

Discussion in 'ASP .Net' started by =?Utf-8?B?SklNLkgu?=, May 22, 2006.

  1. 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,
     
    =?Utf-8?B?SklNLkgu?=, May 22, 2006
    #1
    1. Advertising

  2. 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.
     
    =?Utf-8?B?TGFycnkgQ2hhcmx0b24=?=, May 22, 2006
    #2
    1. Advertising

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


    "Larry Charlton" wrote:

    > 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.
    >
    >
     
    =?Utf-8?B?SklNLkgu?=, May 22, 2006
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jordan

    PDF Creater / Merger

    Jordan, Aug 7, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    646
    Mark Fitzpatrick
    Aug 7, 2005
  2. =?Utf-8?B?SklNLkgu?=

    Question: merger dataset with three tables

    =?Utf-8?B?SklNLkgu?=, Jun 7, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    381
    Ken Cox [Microsoft MVP]
    Jun 8, 2006
  3. mistersulu

    free, python XML merger?

    mistersulu, Dec 11, 2006, in forum: Python
    Replies:
    2
    Views:
    580
    mistersulu
    Dec 13, 2006
  4. fuglyducky

    XML Generator/Merger

    fuglyducky, May 26, 2010, in forum: Ruby
    Replies:
    2
    Views:
    99
    fuglyducky
    May 26, 2010
Loading...

Share This Page