我有一个 datagridview,它通过OleDbDataReader
.
问题如下 将数据读入数据表然后设置datasource = dt
=> 工作
dt.Load(dr);
获取 dt 并将 Linq 应用到它 => 空 GridView
GVMultiple.DataSource = (from myRow in dt.AsEnumerable()
where myRow.Field<string>("State") == "Succeeded"
select myRow)
使Linq.ToList()
=> 显示名称为 "RowError","RowState","Table" 和 "hasErrors" 的列不是我的列
GVMultiple.DataSource = (from myRow in dt.AsEnumerable()
where myRow.Field<string>("State") == "Succeeded"
select myRow).ToList()
将数据读入Object
自定义List then
设置datasource = List
=> 空GridView
while (dr.Read())
{
UserList.Add(new UserInfo()
{
ID = (int)dr["ID"],
UserName = (string)dr["User Name"]
});
}
GVMultiple.DataSource = UserList
有人可以告诉我发生了什么吗?