Deleting record from bindingsource

  • Thread starter Thread starter John
  • Start date Start date
J

John

Hi

I have a winform app with form control bound to a binding source
TblClientsBindingSource. The binding source has a data table as its data
source as per below code;

dAdapter = New OleDbDataAdapter("SELECT * FROM tblClients WHERE ...", Conn)
dAdapter.Fill(dTable)
TblClientsBindingSource.DataSource = dTable

My question is; how do I delete the record currently pointed to by the
binding source from the backend database table tblClients?

Thanks

Regards
 
John said:
Hi

I have a winform app with form control bound to a binding source
TblClientsBindingSource. The binding source has a data table as its data
source as per below code;

dAdapter = New OleDbDataAdapter("SELECT * FROM tblClients WHERE ...", Conn)
dAdapter.Fill(dTable)
TblClientsBindingSource.DataSource = dTable

My question is; how do I delete the record currently pointed to by the
binding source from the backend database table tblClients?

Thanks

Regards

It must be bound to some control. The control is bound on a
DataMemeberValue from the bound source, which would have the record's
key. You need to get the key to the record from the control that's bound
to the bounding source.

If the binding control is like a DataGridView, then you would select the
record in the DataGridView on SelectedIndexChanged event of the control
using SlectedValue that has the key to the record to delete.

You would have a Delete button with a buton click event that will take
the SelectedValue and go back to the database with some routine to
delete the row out of the table by key.

The button click event would have code in it to do your binding source
and bind the source to the control again. The record is deleted, you get
the data from the table again, the record is not there now, and you bind
the new data to the control.
 
Don't use dTable but dTable.DefaultView

To that you can add a rowfilter
dTable.DefaultView.rowfilter = "CustomersName = John"

The Class type of the DefaultView is DataView

Success
 
Back
Top