Reputation: 1361
I have a stored procedure which creates a dataset of two tables. I call this stored procedure from within c# as follows:
DataTable mytable1 = myDataSet.tables[0];
DataTable mytable2 = myDataSet.tables[1];
I would like to be able to pass the 'table name' into the dataset.tables function as I imagine that the stored procedure will one day return additional tables into the dataset.
There have been very similar questions asked here, such as: Give name to table after select and I have found other help sites like: http://odetocode.com/articles/365.aspx
but all the answers I find end up creating additional tables or table variables. I don't want to create any new tables or variables, I simply want to create an alias for my query output.
I have tried giving my tables aliases within the SQL stored procedure but with no success. The names that appear in c# are "Table" and "Table1" respectively.
Everything else about the stored procedure functions properly, I just want it to return different names for the output tables. I have tried the SQL code: (conditions in brackets here for simplicity)
SELECT * FROM myTable1 AS myTable1 WHERE (conditions)
ORDER BY (field) ASC
SELECT * FROM myTable2 INNER JOIN myTable1 ON (join on id field) WHERE (conditions)
ORDER BY (field) ASC
This current SQL code still results in the c# tableName field containing "Table" and "Table1".
Is it completely impossible to rename these query outputs without creating additional tables or table variables?
Upvotes: 0
Views: 1343
Reputation: 6672
Untyped dataset( As in your case) will not give any table name to the datatable. It will be set to default. (i.e. table1, etc). As the Adapter/reader just populates the resulting rows & columns in the schema.
Upvotes: 1