如何从存储过程的结果集中命名数据表 [英] How to name a datatable from the resultset of stored procedure

查看:66
本文介绍了如何从存储过程的结果集中命名数据表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我有一个'n'没有的存储过程。其中的选择查询。当我将其分配给数据集时,我想要将数据表命名为具有我已编写选择查询的表的名称。



对于Ex:下面存储的proc将返回一个包含3个数据表的数据集,我应该将Table1的名称指定为t1,将table2的名称指定为test,将table3指定为test1。



这可能没有硬编码吗?



Hi All,

I have a stored procedure with 'n' no. of select queries in it. When I assign this to a dataset I want to name the datatables as it is with the name of the tables for which I have written the select queries.

For Ex: The below stored proc will return a dataset with 3 datatables and I should assign the name for Table1 as t1 and for table2 as test and table3 as test1.

Is this possible without hard coding?

CREATE PROCEDURE [dbo].[MY_StoredProc]
AS
BEGIN

    select * from t1
    select * from test
    Select * from test1

END







谢谢&问候,

Mathi。




Thanks & Regards,
Mathi.

推荐答案

我认为可以做到。您可以通过将表名作为最后一个列名返回来构建智能。在此之后,您只需要更改数据加载代码。在调用存储过程之后,您只需读取数据的最后一列并将其保存为表名。
I think it could be done. You can build intelligence by returning table names as last column name. After this you simply need to alter your data loading code. After you call the stored procedure you simply read last column of the data and save it as table name.


这里有几种方法虽然不是很好。

如何从数据集中的存储过程返回表名 ^ ]

如何从带有数据适配器的存储过程中获取DataTable名称 [ ^ ]
Here few ways though not great.
How to return table name from stored procedure in dataset[^]
How to get DataTable Names from stored procedure with data adapter[^]


这篇关于如何从存储过程的结果集中命名数据表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆