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.
我正在使用存储过程来填充DataSet。我需要做的是强制填充时创建的DataTable的名称。存储过程返回了多个表。最后一个表是我需要确保在返回时具有特定名称的表。它是通过返回变量的值而不是从任何表中拉出来创建的。
SELECT @Phone as My_800Number
将@Phone选为My_800Number
How can I make this return as table called "D1Header"?
如何将此返回称为“D1Header”表?
2 个解决方案
#1
There is no ADO.NET Native way to do it; ADO.Net assign a generated name with a sequence number, according to this
没有ADO.NET Native方法可以做到这一点;根据此,ADO.Net为生成的名称分配序列号
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 ?
#1
There is no ADO.NET Native way to do it; ADO.Net assign a generated name with a sequence number, according to this
没有ADO.NET Native方法可以做到这一点;根据此,ADO.Net为生成的名称分配序列号
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 ?