I'm confused about binding controls to data sources in VB.Net
Posted on 2006-06-13
I have a question about binding controls to data sources in VB.Net.
First, my background is as an embedded guy and what you do there is allocate all resources, set things up, and hit the proverbial "go" button and then it just sits and spins until power is cut off.
I've read my Wrox book on VB, read forums on this site, read examples, am about half done my first VB-Sql server project and puzzled and puzzled about this whole "bound data control" concept.
Here's what I've puzzled out so far:
Ya got some controls on a form, with bindable properties that you "bind" to a data source, in my case either a DataSet or a DataView thats filled in with an SQL query. Great so far.
There's supposed to be a two-way-path that automagically causes changes to the data in the bound forms to be moved down into the DataSet when the user changes it on the form, and vis-versa. I'm a bit fuzzy on this part.
Sometimes, it seems, you have to re-bind your control to the data source. Not quite clear on just when you have to do this and why.
My Wrox book example rebinds the controls all the time. In fact, it seems that after each and every Update to the Database they re-fill the DataSets and rebind the controls. Now I'm confused. Dont controls stay bound? Do they come unbound somehow and need to be bound back again? Perhaps some super glue and bolts are needed here?
I'm cool on getting data into the DataSets and Views, thats just some SQLCommand objects and that makes sense. You issue a command against the DB, data in the DB changes. Update the DataSet, data there changes. But then there's this bound controls thing. If I must rebind after each update to the dataset, why bind at all?