开发者

Can we convert the list into DataTable in C#?

Can any on开发者_StackOverflow社区e tell me how to convert the List into data table in C# ?


Do you mean generically? There is no automatic way to do it.

But you can manually:

class Person
{
  public int ID {get; set;}
  public string FirstName {get; set;}
...
}

var personsList = new List<Person>();
var dataTable = new DataTable();
dataTable.Columns.Add("ÏD", typeof(int));
dataTable.Columns.Add("FirstName", typeof(string));
...

foreach (var person in personsList)
{
  dataTable.Rows.Add(person.ID, person.FirstName...)
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜