c# - This row has been removed from a table and does not have any data -
this row has been removed table , not have data. beginedit() allow creation of new data in row.
i have method i'm trying delete duplicate rows (using date) , i'm getting above exception code. understand exception means don't understand i'm doing wrong in code cause it. have looked on several times no luck.
using (oldstockratingstableadapter ratingsadapter = new oldstockratingstableadapter()) using (dataset.oldstockratingsdatatable ratingstable = new dataset.oldstockratingsdatatable()) { ratingsadapter.clearbeforefill = true; ratingsadapter.adapter.updatebatchsize = 500; ratingsadapter.fillbymarketsymbol(ratingstable, market, symbol); var masterquery = c in ratingstable c.symbol == symbol && c.market == market select c; list<dataset.oldstockratingsrow> masterrows = masterquery.tolist(); list<dataset.oldstockratingsrow> masterdistinctrows = masterquery.distinctby(i => i.date).tolist(); (int = 0; < masterdistinctrows.count; i++) { var datequery = c in masterrows c.date == masterdistinctrows.elementatordefault(i).date select c; list<dataset.oldstockratingsrow> daterow = datequery.tolist(); // getting exception here if (daterow.count > 1) { (int j = 1; j < daterow.count; j++) { ratingstable.removeoldstockratingsrow(daterow.elementatordefault(j)); console.writeline("stock rating deleted " + symbol + " in " + market + " market!"); } } } // update here dataset.oldstockratingsdatatable tempratingstable = new dataset.oldstockratingsdatatable(); tempratingstable = (dataset.oldstockratingsdatatable)ratingstable.getchanges(); if (tempratingstable != null) { ratingsadapter.adapter.updatecommand.updatedrowsource = updaterowsource.none; ratingsadapter.adapter.deletecommand.updatedrowsource = updaterowsource.none; ratingsadapter.adapter.insertcommand.updatedrowsource = updaterowsource.none; ratingsadapter.update(tempratingstable); tempratingstable.dispose(); console.writeline("stock rating calculations finished " + symbol + " in " + market + " market!"); } }
i don't know code if trying delete duplicates maby code of use you:
delete duplicate query x ( select *, row_number() over(partition <column>, checksum(<columns validate>) order <column>) rn <table> ) delete x rn > 1 //it validate multiple columns if more given
note: code not made me, i'll link origional post here. code posted @dean
.
Comments
Post a Comment