Naming tables in a multi-table dataset using and adapter

S

STom

I am using a SQLDataAdapter to call a stored procedure that has 5 select
statements. I can see that the dataset does contain 5 sets of data, but I
want to name the tables in the dataset that this data goes into.

If I start off doing this:
adpModel = New SqlDataAdapter
hierDS = New DataSet
adpModel.TableMappings.Add("tblModels", "DataTblModels")
adpModel.TableMappings.Add("tblCaseData", "DataTblCaseData")
adpModel.TableMappings.Add("tblCompanyProfile", "DataTblCompanyProfile")
adpModel.TableMappings.Add("tblModelIndustryStandards",
"DataTblModelIndustryStandards")
adpModel.TableMappings.Add("tblDynamicModel", "DataTblDynamicModel")

With adpModel

'add a SelectCommand
..SelectCommand = New SqlCommand
' Specify the Select Command
With .SelectCommand
.CommandType = CommandType.StoredProcedure
.CommandText = "GetModelData"
.Connection = New SqlConnection(lclModel.ConnString)
End With

' Populate the DataSet with the returned data

..Fill(hierDS, "MyModel")

MyModel ends up having MyModel1, MyModel2 etc. How can I tie the table
mappings to the actually dataset being filled? Each table has a ModelID so
basically tblModels is the parent table and the rest are children tables. Do
I have to create a relationship?

Thanks.

STom
 
D

David Sceppa

STom,

The DataAdapter doesn't really know what table or view the
SelectCommand queried to return a particular resultset. By
default, it assumes the first resultset has a name of "Table",
the second resultset "Table1", the third "Table2", etc. So, your
code to populate the DataAdapter's TableMappings collection
should look something like:

With adpModel.TableMappings
.Add("Table", "DataTblModels")
.Add("Table1", "DataTblCaseData")
.Add("Table2", "DataTblCompanyProfile")
.Add("Table3", "DataTblModelIndustryStandards")
.Add("Table4", "DataTblDynamicModel")
End With

I hope this information proves helpful.

David Sceppa
Microsoft
This posting is provided "AS IS" with no warranties,
and confers no rights. You assume all risk for your use.
© 2003 Microsoft Corporation. All rights reserved.
 

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

Top