row deletion in datagrid

  • Thread starter Thread starter agassi
  • Start date Start date
A

agassi

hi guys,
i've already sent a request concerning row deletion in a datagrid.my
problem now is that i've succeded to delete a row from the datagrid,
however the selected row is not actually deleted from the
database.(i'm working with visual C++.NET). here is my code:

mytable->Rows->RemoveAt(dataGrid1->CurrentRowIndex); //mytable is a
DataTable
count = count -1; //number of rows in the datagrid

mydataset->AcceptChanges();
mycommandbuilder->GetDeleteCommand(); //mycommandbuilder is an
OleDbCommandBuilder
myadapter->Update(mydataset); //myadapter is a DataAdapter
dataGrid1->Refresh();
 
Deleting and Removeing are two totally different functions.
http://www.knowdotnet.com/articles/efficient_pt4.html This may help . In a
smiliar note, you are calling AcceptChanges before Update so there's no way
that the DataAdapter will no to remove this code. Moreover, Remove takes it
out of the collection whereas delete marks the rowstate to Deleted (whcih is
necessary for the Adapter to call the Delete command agasint that row).

That article will explain both issues but you definitely don't need to call
AcceptChanges in the way you are, this virtually guarantees that all of your
changes, not just the deletions, will never be committed with that Update
command.

--

W.G. Ryan, eMVP

http://forums.devbuzz.com/
http://www.knowdotnet.com/williamryan.html
http://www.msmvps.com/WilliamRyan/
 
Back
Top