0

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?

1
  • 2
    You'll need to work with strongly-typed datasets (see: support.microsoft.com/kb/320714) to reference the items in the Tables collection by name. Commented Sep 18, 2014 at 13:48

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.