[英]dataset c# datatable
A stored procedure returns multiple tables, the result set is assigned to a DataSet. 一个存储过程返回多个表,结果集分配给一个数据集。 Can I access the tables in the DataSet with each table's name? 我可以使用每个表的名称访问数据集中的表吗?
For eg.:- 例如:-
DataSet ds = Select(despatch_Packing_ID); 数据集ds =选择(despatch_Packing_ID);
The DataSet contains 4 tables. 数据集包含4个表。
I am imposed to access the tables as DataTable dtSales = ds.Tables[0]; 我被迫以DataTable dtSales = ds.Tables [0];的形式访问表。
How can I access the DataTable as DataTable dtSales = ds.Tables["Sales"]; 如何以DataTable dtSales = ds.Tables [“ Sales”];的形式访问DataTable // Sales is tables where from I get data // Sales是从中获取数据的表
Thanks in advance. 提前致谢。
By default the table names generated by a DbDataAdapter will have the names "Table", "Table1", "Table2", ... 默认情况下,由DbDataAdapter生成的表名称将具有名称“ Table”,“ Table1”,“ Table2”,...
You can override this by specifying DataTableMappings . 您可以通过指定DataTableMappings覆盖它。
For example: 例如:
DbDataAdapter adapter = ...
...
adapter.TableMappings.Add("Table", "Sales");
adapter.TableMappings.Add("Table1", "Customers");
...
adapter.Fill(myDataSet);
...
The problem is that a query in a stored procedure can span multiple tables and views or even simply return a single value. 问题在于存储过程中的查询可以跨越多个表和视图,甚至可以简单地返回单个值。
How would the DataTable get its name then? 那么,DataTable将如何获得其名称?
I suppose it doesn't work, because returned data may be produced from multiple joined tables. 我想它不起作用,因为返回的数据可能是由多个联接表产生的。 In such case there is no way to identify them by name. 在这种情况下,无法通过名称识别它们。 But I haven't checked myself, so it is just my guess. 但是我还没有检查自己,所以这只是我的猜测。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.