This tip explains how to populate a Typed Dataset from a Stored Procedure, which returns multiple result sets.
We need to use the DataAdapter TableMappings collection to map the generic tables to the schema, which is defined in the typed Dataset. When the Data Adapter is used to fill a dataset, the dataset is filled with tables named as Table, Table1, Table2 and so on. So typed Datasets can’t be populated normally.
The Stored Procedure
CREATE PROCEDURE getData
SELECT * FROM Employees;
SELECT * FROM Departments;
Shown above is the Stored Procedure, which will be used to populate two tables in the Typed Dataset given below.
The Typed Dataset
Create a Typed Dataset by dragging and dropping the two tables from the Server Explorer in Design Mode.
The following piece of code will help us to populate a typed Dataset directly with the Fill method of the Data Adapter.
Dim sStr as String = “Your DB Connection String”
Dim oDA as New SqlDataAdapter("getData", oConn)
oDA.SelectCommand.CommandType = CommandType.StoredProcedure
oDA.TableMappings.Add("Table1", " Departments")
Dim oDs As New EmpDept()
Hope this is useful. Happy Coding!!!!