你怎么能说出你在一个存储过程返回的数据集的表?

你怎么能说出你在一个存储过程返回的数据集的表?

问题描述:

我有以下存储过程

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

该数据集表属性也得到了一个访问由字符串(而不是INT)。

the dataset Tables property also got an accessor by string (instead of int).

是否有可能使指定表中的SQL code的名字,这样我就可以,而不是这样写:

     DataTable datatableA = ds.Tables["NametbA"];
     DataTable datatableB = ds.Tables["NametbB"];

我使用的是SQL Server 2008中,如果有差别。

I'm using SQL server 2008, if that makes a difference.

据我所知,从存储过程,你不能这样做。一旦你已经检索到的数据集,你可以,但是,设置名称,然后使用他们从那时候开始。

As far as I know, from the stored proc, you can't do that. You can, however, set the names once you have retrieved the DataSet, and then use them from then on.

ds.Tables[0].TableName = "NametbA";