Link to home
Start Free TrialLog in
Avatar of tbaseflug
tbaseflugFlag for United States of America

asked on

1 Dataset, 2 Datatables - Example Needed

I need a simple / best practices example of creating a dataset and filling it with 2 datatables, from two different stored procedures.
Avatar of tbaseflug
tbaseflug
Flag of United States of America image

ASKER

Need it in VB.NET
Avatar of AerosSaga
AerosSaga

what is the relation between the two tables?
if its a foreign key relation look here:
http://aspnet.4guysfromrolla.com/articles/101602-1.aspx
so create a relation or merge;)

Aeros
AerosSaga -

I like the idea of merging the two - I am trying to wrap them into a function - My code is below - how would I return the resulting combination?
------------------------
    Public Shared Function NavMenuGET3() As DataSet

        'Open a connection to Northwind
        Dim objConn As New SqlConnection(ConfigurationSettings.AppSettings("HODEV1ConnectionString"))
        objConn.Open()

        'Create the stored procedure command object
        Dim objCmd As New SqlCommand("usp_Menu_GET2", objConn)
        objCmd.CommandType = CommandType.StoredProcedure

        Dim objCmd2 As New SqlCommand("usp_MyJobPostings_GET", objConn)
        objCmd.CommandType = CommandType.StoredProcedure
        objCmd2.Parameters.AddWithValue("@PostedByID", 19829)

        'create DataAdapter and DataSet objects
        Dim objDA As New SqlDataAdapter(objCmd)
        Dim objDS As New DataSet("Results")

        Dim objDA2 As New SqlDataAdapter(objCmd2)
        Dim objDS2 As New DataSet("Results2")

        'fill the dataset
        objDA.Fill(objDS)

        objDS.Merge(objDS2)

        Return objDS

    End Function
depending on your data that looks ok, have you tried to run this yet.  You may need to establish some relations.

ASKER CERTIFIED SOLUTION
Avatar of AerosSaga
AerosSaga

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial