更新时间:2023-02-24 17:31:04
如果您需要返回DataSet
,而您只需要DataTable
,则可以添加DataTable
到虚拟DataSet
并返回。这是一个例子:
If you need to return aDataSet
, and all you have is aDataTable
, you can add theDataTable
to a dummyDataSet
and return that. Here''s an example:
public DataSet DoSomething()
{
DataTable people = GetPeopleWhoMatchSomeCriteria();
DataSet dummySet = new DataSet();
dummySet.Tables.Add(people);
return dummySet;
}
另一种方法是将返回类型从 DataSet
更改为 DataTable
。
The alternative is to change the return type from DataSet
to DataTable
.
你不能将DataTable转换为DataSet。
you can''t cast a DataTable to DataSet.