tbaseflug
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.
what is the relation between the two tables?
if its a foreign key relation look here:
http://aspnet.4guysfromrolla.com/articles/101602-1.aspx
http://aspnet.4guysfromrolla.com/articles/101602-1.aspx
depending on your situation you might consider merging the dataset:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemdatadatasetclassmergetopic.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon/html/vbtskmergingdatasets.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemdatadatasetclassmergetopic.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon/html/vbtskmergingdatasets.asp
so create a relation or merge;)
Aeros
Aeros
ASKER
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(Configuratio nSettings. AppSetting s("HODEV1C onnectionS tring"))
objConn.Open()
'Create the stored procedure command object
Dim objCmd As New SqlCommand("usp_Menu_GET2" , objConn)
objCmd.CommandType = CommandType.StoredProcedur e
Dim objCmd2 As New SqlCommand("usp_MyJobPosti ngs_GET", objConn)
objCmd.CommandType = CommandType.StoredProcedur e
objCmd2.Parameters.AddWith Value("@Po stedByID", 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
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(Configuratio
objConn.Open()
'Create the stored procedure command object
Dim objCmd As New SqlCommand("usp_Menu_GET2"
objCmd.CommandType = CommandType.StoredProcedur
Dim objCmd2 As New SqlCommand("usp_MyJobPosti
objCmd.CommandType = CommandType.StoredProcedur
objCmd2.Parameters.AddWith
'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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER