Bindingsource and writing to database

pachjo

Well-known member
Joined
Dec 12, 2006
Messages
370
Programming Experience
10+
I have set a combobox as follows:

VB.NET:
  'set the bindings for the transaction description combobox

   Me.cboTransDescription.DataSource = glb_dbTransactionDescBinding

   Me.cboTransDescription.DisplayMember = "tran_description"

   Me.cboTransDescription.ValueMember = "tran_id"


This successfully populates the combobox and also allows me to add items which appear in the combobox.

I want to be able to delete the selected item in the combobox and found on this site that one should use a bindingsource to do so which I did and it does get removed from the combobox but I have found that neither adding or deleting affects the actual database.

Here is how I setup the bindingsource:

VB.NET:
glb_taTransactionDesc.Fill(glb_dtTransactionDesc)

glb_dbTransactionDescBinding.DataSource = glb_dtTransactionDesc

and here is how I delete a record from the combobox but does not affect the database:

VB.NET:
glb_dbTransactionDescBinding.Remove(glb_dbTransactionDescBinding.Current)

glb_taTransactionDesc.Update(glb_dtTransactionDesc)

Have I lost the plot and missed something important?

Thanks
 
The binding source maintains a local list that is based on, but not actually the underlying source data list. When you tell the bindingsource to remove the cuirrent item from its own list, it doesnt mark the underlying item as deleted..

I recommend you try one of these, instead:

DirectCast(myBindingSource.Current, DataRowView).Delete()
DirectCast(myBindingSource.Current, DataRowView).Row.Delete()


They should work synonymously
 
Back
Top