How can you name the Dataset#39;s Tables you return in a stored proc?(如何命名在存储过程中返回的数据集表?)
问题描述
我有以下存储过程
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];
数据集 Tables 属性也通过字符串(而不是 int)获得访问器.
the dataset Tables property also got an accessor by string (instead of int).
是否可以在 SQL 代码中指定表的名称,以便我可以改为这样写:
DataTable datatableA = ds.Tables["NametbA"];
DataTable datatableB = ds.Tables["NametbB"];
我使用的是 SQL Server 2008,如果这会有所不同的话.
I'm using SQL server 2008, if that makes a difference.
推荐答案
据我所知,从存储过程中,你不能这样做.但是,您可以在检索到 DataSet 后设置名称,然后从那时起使用它们.
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";
这篇关于如何命名在存储过程中返回的数据集表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何命名在存储过程中返回的数据集表?
基础教程推荐
- WPF 模态进度窗口 2022-01-01
- .NET SerialPort DataReceived 事件未触发 2022-01-01
- Azure Functions:CosmosDBTrigger 未在 Visual Studio 中触发 2022-01-01
- 如何使用 .Net 检查 Active Directory 服务器是否已启动并正在运行? 2022-01-01
- 如果有人提交恶意软件Nuget包怎么办? 2022-01-01
- 禁止输入少量字符,例如'<'、'&a 2022-01-01
- Moq It.Is<>不匹配 2022-01-01
- C# 从 List<List<int>> 中删除重 2022-01-01
- 我应该在后面的代码中直接使用 Linq To SQL 还是使 2022-01-01
- 当值可以是对象或空数组时反序列化 JSON 2022-01-01
