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

发布于 2024-08-31 13:15:27 字数 996 浏览 6 评论 0原文

我使用一个数据集来存储加载时需要的 15 个表。当我使用存储过程填充所有表时,它返回所有表,但表的名称并不与数据库中的实际表名称相同。

它采用表名称为 Table1、Table2、Table3 的所有表...

我希望它们的名称与表中实际的名称相同。

SELECT PK_GUEST_TYPE, [DESCRIPTION] FROM L_GUEST_TYPE
SELECT PK_AGE_GROUP_ID, AGE_GROUP FROM L_AGE_GROUP
SELECT PK_COMPANY_ID, COMPANY_NAME FROM M_COMPANY
SELECT PK_COUNTRY_ID, COUNTRY FROM L_COUNTRY
SELECT PK_EYE_COLOR_ID, [DESCRIPTION] FROM L_EYE_COLOR
SELECT PK_GENDER_ID, [DESCRIPTION] FROM L_GENDER
SELECT PK_HAIR_COLOR_ID, [DESCRIPTION] FROM L_HAIR_COLOR
SELECT PK_STATE_PROVONCE_ID, [DESCRIPTION] FROM L_STATE_PROVINCE
SELECT PK_STATUS_ID, [DESCRIPTION] FROM L_STATUS

SELECT PK_TITLE_ID, [DESCRIPTION] FROM L_TITLE
SELECT PK_TOWER_ID, [DESCRIPTION] FROM M_TOWER
SELECT PK_CITY_ID, [DESCRIPTION] FROM L_CITY
SELECT PK_REGISTER_TYPE_ID, [DESCRIPTION] FROM L_REGISTER_TYPE

这是我用于填充数据集的前端编码。

             OpenConnection();
             adp.Fill(ds);
             CloseConnection(true);

I used a dataset to store 15 tables that I need at the time of loading. When i filled all the tables using stored procedure it returns me all the table but name of the table doesn't comes as that of actual table name in a database.

It takes all the table with table name as Table1, Table2, Table3...

I want them to be with the name as they actually are in table.

SELECT PK_GUEST_TYPE, [DESCRIPTION] FROM L_GUEST_TYPE
SELECT PK_AGE_GROUP_ID, AGE_GROUP FROM L_AGE_GROUP
SELECT PK_COMPANY_ID, COMPANY_NAME FROM M_COMPANY
SELECT PK_COUNTRY_ID, COUNTRY FROM L_COUNTRY
SELECT PK_EYE_COLOR_ID, [DESCRIPTION] FROM L_EYE_COLOR
SELECT PK_GENDER_ID, [DESCRIPTION] FROM L_GENDER
SELECT PK_HAIR_COLOR_ID, [DESCRIPTION] FROM L_HAIR_COLOR
SELECT PK_STATE_PROVONCE_ID, [DESCRIPTION] FROM L_STATE_PROVINCE
SELECT PK_STATUS_ID, [DESCRIPTION] FROM L_STATUS

SELECT PK_TITLE_ID, [DESCRIPTION] FROM L_TITLE
SELECT PK_TOWER_ID, [DESCRIPTION] FROM M_TOWER
SELECT PK_CITY_ID, [DESCRIPTION] FROM L_CITY
SELECT PK_REGISTER_TYPE_ID, [DESCRIPTION] FROM L_REGISTER_TYPE

Here is my frontend coding to fill dataset.

             OpenConnection();
             adp.Fill(ds);
             CloseConnection(true);

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

你在看孤独的风景 2024-09-07 13:15:27

解决

Create procedure psfoo ()
AS
select * ,'tbA' as TableName from tbA
select * ,'tbB' as TableName from tbB

可能这可以通过在返回表中添加额外的列然后在 C# 代码中

 foreach (DataTable dt in ds.Tables)
    {
        if (dt.Rows[0]["TableName"].ToString().Contains("tbA"))
        {

        }
        else if (dt.Rows[0]["TableName"].ToString().Contains("tbB"))
        {

        }
    }

May be this could be the work around by adding an extra column in returning table

Create procedure psfoo ()
AS
select * ,'tbA' as TableName from tbA
select * ,'tbB' as TableName from tbB

Then in C# code

 foreach (DataTable dt in ds.Tables)
    {
        if (dt.Rows[0]["TableName"].ToString().Contains("tbA"))
        {

        }
        else if (dt.Rows[0]["TableName"].ToString().Contains("tbB"))
        {

        }
    }
百思不得你姐 2024-09-07 13:15:27

我会投入时间使用 类型化数据集,会产生很多事情变得容易多了。
请记住,您可能会在一三个月内再次使用此代码。 :)

I would have invested time to use typed dataset, makes a lot of things much easier.
Remember you probarly will come back to this code in a month or three. :)

[浮城] 2024-09-07 13:15:27

让第一个(或最后一个)表有一个表名称的 meta 表,其顺序与后面(或前面)的表相同。

Have the first (or last) table a meta table of table names in the same order as the following (or preceding) tables.

心舞飞扬 2024-09-07 13:15:27

MS 表映射完全是个笑话。
有什么区别?

ds.Table(0)
ds.Table("Table")
ds.Table("Customer")

当我们无法保证应用程序中返回的表的顺序时,
需要的是 STRONG-NAME 匹配......查看我的解决方案< /a>

MS table mapping is a total joke.
What is the difference between

ds.Table(0)
ds.Table("Table")
ds.Table("Customer")

when we have no guarantee of the order of tables returned within our application.
The need is a STRONG-NAME match.... See my solution

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文