How to return table name from stored procedure in dataset

自闭症网瘾萝莉.ら 提交于 2019-12-20 03:43:06

问题


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);

回答1:


Probably this would help Mapping Data Source Tables to Dataset Tables




回答2:


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"))
        {

        }
    }



回答3:


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. :)




回答4:


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




回答5:


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



来源:https://stackoverflow.com/questions/2801799/how-to-return-table-name-from-stored-procedure-in-dataset

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