in the stored procedure:
select CH.PrimaryKey, CH.Name, NULL "CustomerHeader" from CustomerHeader "CH"; -- select CD.PrimaryKey, CD.ShipTo, NULL "CustomerDetail" from CustomerDetail "CD"; -- select *, NULL "Orders" from OrderTable;
in Vb.Net code:
Dim ds As DataSet = Nothing ds = SqlExecute(); Dim dtCustHeader As DataTable = Nothing Dim dtCustDetail As DataTable = Nothing Dim dtOrders As DataTable = Nothing For Each dt As DataTable In ds.tables Select Case True Case dt.Columns.Contains("CustomerHeader") dtCustHeader = dt Case dt.Columns.Contains("CustomerDetail") dtCustDetail = dt Case dt.Columns.Contains("Orders") dtOrders = dt End Select Next
Kinda SILLY (OR STUPID), which cannot be called tables in the result set. But this will lead you there without a HUGE byte repeating the name of the table in each row.
The remaining overhead passes a NULL value for each row. Perhaps passing the BIT value will be even less ...
And the alternative is to always use column (0): in SQL:
select NULL "CustomerDetail", CustName,Addr1,Addr2... from CustomerDetail;
in vb.net:
Dim ds As DataSet = Nothing ds = SqlExecute(); Dim dtCustHeader As DataTable = Nothing Dim dtCustDetail As DataTable = Nothing Dim dtOrders As DataTable = Nothing For Each dt As DataTable In ds.Tables Dim tblName As String = dt.Columns(0).ColumnName Select Case tblName.ToUpper Case "CUSTOMERDETAIL" : dtCustHeader = dt Case "CUSTOMERDETAIL" : dtCustDetail = dt Case "ORDERS" : dtOrders = dt End Select Next
These methods get your table names even if the query returns null rows.
but best for the last ... the way the actual name of the tables in the data set is automatically, every time FROM SQL STORED PROCEDURE (using your code):
Dim ds As DataSet = Nothing ds = SqlExecute(); For Each dt As DataTable In ds.Tables dt.TableName = dt.Columns(0).ColumnName Next
After that, you can access your tables with a name that you control in the stored procedure ... as it should have been from the first day!
EDIT : custom implementation: Name the first column in the template "TN: Client". Your obsolete stored procedures work just fine, only affecting the stored procedures you want to modify.
For Each dt As DataTable In mo_LastDataset.Tables Dim tblName() As String = dt.Columns(0).ColumnName.Split(":") If tblName.Length >= 2 AndAlso tblName(0).ToUpper = "TN" Then dt.TableName = tblName(1) End If Next
... david ...