DataSet's Table name from a Stored Procedure

匆匆过客 提交于 2019-12-24 06:51:32

问题


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"?


回答1:


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";
}



回答2:


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 ?



来源:https://stackoverflow.com/questions/804443/datasets-table-name-from-a-stored-procedure

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!