Tuesday 21 May 2019

loading multiple tables within dataset using store producer

CREATE PROCEDURE testSP
AS
BEGIN
 SELECT CategoryID,CategoryName,Description FROM Categories 
 SELECT SupplierID,CompanyName,ContactName FROM Suppliers
 SELECT ProductID,ProductName,CategoryID,SupplierID FROM Products
END
GO
C#
using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["NorthwindNewConnectionString"].ToString()))
{
 SqlDataAdapter da = new SqlDataAdapter("testSP",conn);
 da.SelectCommand.CommandType = CommandType.StoredProcedure;

 DataSet ds = new DataSet();

 da.Fill(ds);

 DataTable dtCategories = ds.Tables[0];
 DataTable dtSuppliers = ds.Tables[1];
 DataTable dtProducts = ds.Tables[2];
}

No comments:

Post a Comment