I'm not sure if I'm asking the right question here, but after trying various things for the last few hours with no joy I come here seeking greater wisdom.
I have a form with various text boxes which are bound to a binding source and are used to display and update the associated rows in a database.
The code I have looks like this:
So this works great, and does what I want it to do. The only problem is, I can only use it once. If I try to run the same code again I get an error saying the bindings already exist. If I only do the database query (with different id) then I get no errors but it is still only showing the data for the first person I viewed.
How do I update the page so when I re-run the db query with a new id, all my textboxes update to reflect the new values?
I've tried all sorts of things such as databindings.remove and bsourceCustomer.ResetBindings(true); but none of it appears to yield the desired effect.
What have I missed?
I have a form with various text boxes which are bound to a binding source and are used to display and update the associated rows in a database.
The code I have looks like this:
C#:
//Dataset
DataSet dsCustomer;
//Get data on currently selected member
dsCustomer = dbCustomer.queryDb("SELECT * FROM customer WHERE id = ..
//Create new binding source
bsourceCustomer = new BindingSource();
//Set datasource for binding sources
bsourceCustomer.DataSource = dsCustomer.Tables["customer"];
//Bind customer text/comboboxes to binding source (varchar datatype)
txtCustomerid.DataBindings.Add("Text", bsourceCustomer, "id");
// lots more lines like the above - one for each text box
So this works great, and does what I want it to do. The only problem is, I can only use it once. If I try to run the same code again I get an error saying the bindings already exist. If I only do the database query (with different id) then I get no errors but it is still only showing the data for the first person I viewed.
How do I update the page so when I re-run the db query with a new id, all my textboxes update to reflect the new values?
I've tried all sorts of things such as databindings.remove and bsourceCustomer.ResetBindings(true); but none of it appears to yield the desired effect.
What have I missed?