Deleting record from bindingsource

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
 
M

Mr. Arnold

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.
 
C

Cor Ligthert[MVP]

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
 

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