c# - Convert DataSet to List -
here c# code
employee objemp = new employee(); list<employee> emplist = new list<employee>(); foreach (datarow dr in ds.tables[0].rows) { emplist.add(new employee { name = convert.tostring(dr["name"]), age = convert.toint32(dr["age"]) }); }
it uses loop create list dataset.is there direct method or shorter method or 1 line code convert dataset list
try this:
var emplist = ds.tables[0].asenumerable().select(datarow => new employee{name = datarow.field<string>("name")}).tolist();
Comments
Post a Comment