row deletion in datagrid

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();
 
W

William Ryan eMVP

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/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top