更新时间:2023-02-17 18:07:14
看到它,会帮助你..
转换内容的数据网格视图到列表中的清晰度 [ ^ ]
how can i bind gridview to list<>:
what i have done is as follows:
var NameList = (from r in dataset.Tables[0].AsEnumerable()
select new
{
Name = r.Field<string>("name"),
Age = r.Field<string>("age"),
Salary = r.Field<string>("salary"),
City = r.Field<string>("city")
}).ToList(string);
return NameList;
error is coming like :
Quote:Error 1 Invalid expression term 'string' d:\substituteofsqlhelp (2)\datalayer\DataLayer.cs 50 49 datalayer
why ?
what i had done earlier was :
//List<string> NameList = (from r in dataset.Tables[0].AsEnumerable() // select r.Field<string>("name")+ r.Field<string>("age")+r.Field<string>("salary")+r.Field<string>("city")).ToList(); //return NameList;
but gives concatenated output. after AMY's help i wrote above code but again error was coming list like:
Quote:Error 1 Cannot implicitly convert type 'System.Collections.Generic.List<anonymoustype#1>' to 'System.Collections.Generic.List<string>' d:\substituteofsqlhelp (2)\datalayer\DataLayer.cs 51 25 datalayer
how can i solve the problem . Thanx.
See it,will help you..
Convert-contents-of-datagridview-to-list-in-c-sharp[^]