嗨,我是C#的新手,想知道是否有某些东西可以简化我想要做的事情。 我正在使用此示例从类创建数据表。 Using Reflection to create a DataTable from a Class?
问题:
我想在我的数据表中添加行而不单独填充每个col。 如何从对象向此数据表添加行?
样品:
DataTable dogTable = CreateDataTable(typeof(Dog));
grid.datasource = dogTable;
...
private void populateData(Dog newDog)
{
DataRow row;
...
//How do i populate without without going through each field ?? possible ?
//Since datatable was created from Dog there is a one to one relationship betwee
//datatable and dog class.
dogTable.Rows.Add(row);
}
有没有一种简单的方法可以将newDog放入表中?