Question

I am using a stored procedure to fill a DataSet. What I need to do is force the name of the DataTable that is created when filled. There are multiple tables returned from the Stored Procedure. The last table is the one I need to make sure has a specific name when returned. It is created by returning a value of a variable and not pulling from any tables.

SELECT @Phone as My_800Number

How can I make this return as table called "D1Header"?

Was it helpful?

Solution

There is no ADO.NET Native way to do it; ADO.Net assign a generated name with a sequence number, according to this

You can workaround it... if you say you need the last table with a specific name, you can do:

if (ds.Tables.Count > 0) {
  ds.Tables[ds.Tables.Count - 1].TableName = "name";
}

OTHER TIPS

Could use an enum of the table names and reference that in your table reference rather than the table itself.

ds.tables(myEnum.Contacts).rows ?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top