How can you name the Dataset's Tables you return in a stored proc ?
Posted
by Brann
on Stack Overflow
See other posts from Stack Overflow
or by Brann
Published on 2009-02-26T10:32:00Z
Indexed on
2010/04/11
10:33 UTC
Read the original article
Hit count: 346
I've got the following stored procedure
Create procedure psfoo ()
AS
select * from tbA
select * from tbB
I'm then accessing the data this way :
Sql Command mySqlCommand = new SqlCommand("psfoo" , DbConnection)
DataSet ds = new DataSet();
mySqlCommand.CommandType = CommandType.StoredProcedure;
SqlDataAdapter mySqlDataAdapter = new SqlDataAdapter();
mySqlDataAdapter.SelectCommand = mySqlCommand;
mySqlDataAdapter.Fill(ds);
Now, when I want to access my tables, I have to do this :
DataTable datatableA = ds.Tables[0];
DataTable datatableB = ds.Tables[1];
the dataset Tables property also got an accessor by string (instead of int).
Is it possible so specify the name of the tables in the SQL code, so that I can instead write this :
DataTable datatableA = ds.Tables["NametbA"];
DataTable datatableB = ds.Tables["NametbB"];
I'm using SQL server 2008, if that makes a difference.
© Stack Overflow or respective owner