如何将DataSet转换为List?
我有一个数据集 ds 和一个 ArrayList newpath 列表,我想将 ds 添加(分配)到 newpath 这怎么可能。
public List<ArrayList> newpath
{
set { ViewState["newpath"] = value; }
get
{
if (ViewState["newpath"] == null)
return new List<ArrayList>();
else
return (List<ArrayList>)ViewState["newpath"];
}
}
我正在尝试
foreach (DataRow dataRow in Ftb.Rows)//Ftb is datatable
{
newpath.Add(dataRow);//newpath is List<ArrayList>
}
,
foreach (DataRow dRow in ds.Tables[0].Rows)
{
newpath.Add(dRow);
}
如果我按照上面的方式做,那么我会收到错误 “‘System.Collections.Generic.List.Add(System.Collections.ArrayList)’的最佳重载方法匹配有一些无效参数”
如果以某种方式请帮助我..该怎么做
I have a dataset ds and a List of ArrayList newpath i want to add(assign) ds to newpath
how is that possible.
public List<ArrayList> newpath
{
set { ViewState["newpath"] = value; }
get
{
if (ViewState["newpath"] == null)
return new List<ArrayList>();
else
return (List<ArrayList>)ViewState["newpath"];
}
}
i am trying with
foreach (DataRow dataRow in Ftb.Rows)//Ftb is datatable
{
newpath.Add(dataRow);//newpath is List<ArrayList>
}
and
foreach (DataRow dRow in ds.Tables[0].Rows)
{
newpath.Add(dRow);
}
if i am doing like above way then i am getting the error
"The best overloaded method match for 'System.Collections.Generic.List.Add(System.Collections.ArrayList)' has some invalid arguments"
Please help me if in someway.. how to do that
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我假设您希望
newpath
中的每个项目都包含每行的列值?如果是这样,请使用这样的代码:
I assume you want each item in
newpath
to contain the column values of each row?If so, have such code instead:
将 newpath 从 更改
为
change newpath from
to
从您发布的代码来看,您的 newpath 变量似乎是 ArrayList 列表。因此,当您尝试添加
dRow
(即DataRow
)时,您会收到错误,因为它不是ArrayList
。如果您想添加 DataRows,我认为
newpath
应该是DataRow
列表。如果你想用 DataRow 中的数据填充 ArrayList,你需要这样的东西 -From the code you've posted it looks as if your
newpath
variable is a list of ArrayLists. So when you try to adddRow
which isDataRow
you're getting an error as it's not anArrayList
.If you want to add DataRows I think
newpath
should be a list ofDataRow
. If you wanted to populate the ArrayList with data from the DataRow you'd need something like this -我已经修改了@Shadow Wizard代码,现在它工作正常
I have modified @Shadow Wizard code and now its working fine