Reputation: 21108
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);
Upvotes: 2
Views: 8655
Reputation: 61
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
Upvotes: 0
Reputation: 2252
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"))
{
}
}
Upvotes: 3
Reputation: 9986
Probably this would help Mapping Data Source Tables to Dataset Tables
Upvotes: 2
Reputation: 818
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. :)
Upvotes: 1
Reputation: 29668
Have the first (or last) table a meta
table of table names in the same order as the following (or preceding) tables.
Upvotes: 0