How to return table name from stored procedure in dataset
I used a dataset to store 15 tables that I need at load time. When I populated all the tables using the stored procedure, it returns the entire table to me, but the table name is not the same as the actual table name in the database.
It accepts the whole table with the table name as Table1, Table2, Table3 ...
I want them to be named as they are actually in the 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 interface for populating the dataset.
OpenConnection();
adp.Fill(ds);
CloseConnection(true);
a source to share
I'd take the time to use a typed dataset , it makes a lot easier. Remember, you'll probably come back to this code in a month or three. :)
a source to share
Maybe this could be the problem by adding an extra column to the return 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"))
{
}
}
a source to share
The MS table display is a common joke. What's the difference between
ds.Table(0)
ds.Table("Table")
ds.Table("Customer")
when we do not guarantee the order of the tables returned in our application. The need is STRONG-NAME matching .... See my solution
a source to share