C# WPF and Sqlite: Datagrid displays last table recording when trying to read from an sqlite database table -
i can't figure why data grid displaying last table recording sqlite database. here code i've writen.
observablecollection<activity> _activitieslist = new observablecollection<activity>(); while (reader.read()) { _act.name = reader.getstring(reader.getordinal("activity")); _act.customer = reader.getstring(reader.getordinal("activitycustomer")); _act.activitytpe = reader.getstring(reader.getordinal("activitynature")); string st = reader.getstring(reader.getordinal("startedat")); _act.startedat = convert.todatetime(st); string et = reader.getstring(reader.getordinal("finishedat")); _act.endedat = convert.todatetime(et); //string _ratio = reader.getstring(reader.getordinal("activityratio")); //_act.activityratio = convert.todouble(_ratio); _act.notes = reader.getstring(reader.getordinal("notes")); string _hldy = reader.getstring(reader.getordinal("holiday")); _act.isholiday = convert.toboolean(_hldy); _activitieslist.add(_act); } activitiesdatagrid.itemssource=_activitieslist;
can create new object instance "activity" class in inside while loop.
observablecollection<activity> _activitieslist = new observablecollection<activity>(); **while (reader.read()) { ***_act = new activity();*** _act.name = reader.getstring(reader.getordinal("activity")); .... .... }**
Comments
Post a Comment