BindingSource Removing Current Row

  • Thread starter msnews.microsoft.com
  • Start date
M

msnews.microsoft.com

Greetings

I have a a simple application with 1 form. On my form I use a
BindingSource to bind a database table to a "table (gridDataView)" (one
in the database, one on my form, 2 different types of tables).

I want to remove the current row I tried :

GrantsBindingSource.RemoveCurrent();

this removes it from the list on the form, but does not remove it from
the database, so I tried this :

GrantsBindingSource.RemoveCurrent();
GrantsBindingSource.EndEdit();

this also did not work, so finally I uesd the following :

DataRowView drv = (DataRowView)grantsBindingSource.Current;
AcroDataSet.GrantsRow row = (AcroDataSet.GrantsRow)drv.Row;
grantsTableAdapter.Delete(row.login, row.application, row.level);
grantsBindingSource.RemoveCurrent();

This "works" but seems like a lot to just remove the current record, is
there a "better" way? some way I can use the BindingSource natively and
remove the item from the "list" and the database at the same time?

thanks in advance
troy
 
N

Nicholas Paldino [.NET/C# MVP]

Troy,

No, there is not. The binding source connects to a disconnected data
set. When you remove the current row, assuming that you are using a DataSet
or DataTable, it sets the state of the row to delete. You have to pass that
DataSet/DataTable to a data adapter in order to have the database updated.
 
T

Troy Bull

Nicholas said:
Troy,

No, there is not. The binding source connects to a disconnected data
set. When you remove the current row, assuming that you are using a
DataSet or DataTable, it sets the state of the row to delete. You have
to pass that DataSet/DataTable to a data adapter in order to have the
database updated.

So, am i doing this incorrectly? How do I pass the DataSet associated
with my BindingSource to a dataadapter?

Thanks
troy
 
N

Nicholas Paldino [.NET/C# MVP]

Troy,

The way you are doing it is right. I was just explaining why that way
was right.
 

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