I have not worked with datasets before. I use a lot of LINQ / Entity Framework.
Here is the code I wrote (this is part of the switch):
if (!DataHelper.DataSourceIsEmpty(dsUp)) { //get datarow collection from dataset DataRowCollection drc = dsUp.Tables[0].Rows; //Loop through dataset foreach (DataRow dr in drc) { //get current dataset row sortid int sortID = Convert.ToInt32(dr["SortID"]); { //if its the row above then minus one if (sortID == nodeAbove) { int newID = Convert.ToInt32(dr["SortID"].ToString()); newID--; dr["SortID"] = newID; //TODO: save changes back to original ds } } } } break;
I tried things like:
- dr.AcceptChanges
- dsUp.AcceptChanges (dr)
- drc.copyto (dsUP)
- dsUp.Merge (DRC)
and many other similar attempts that did not work. When googling for this topic all the results that I found use a table adapter ... since im works in cms, I get my data as follows:
DataSet dsUp = tree.SelectNodes(CurrentSite, path, cultureCode, true, classnames, where, orderby);
Any help on making changes saved back to db would be greatly appreciated by Cheers.
After posting, I also tried this method, which unfortunately did not work:
//dataset to hold results before merge DataSet DSResults = tree.SelectNodes(CMSContext.CurrentSite.SiteName, path, cultureCode, true, classnames); DSResults.Clear(); if (!DataHelper.DataSourceIsEmpty(dsUp)) { //get datarow collection from dataset DataRowCollection drc = dsUp.Tables[0].Rows; //Loop through dataset foreach (DataRow dr in drc) { //get current dataset row sortid int sortID = Convert.ToInt32(dr["SortID"]); { //if its the row above then minus one if (sortID == nodeAbove) { int newID = Convert.ToInt32(dr["SortID"].ToString()); newID--; dr["SortID"] = newID; dr.AcceptChanges(); DSResults.Tables[0].Rows.Add(dr); } } } } //save changes back to original ds dsUp.Merge(DSResults); dsUp.AcceptChanges(); break;
source share