Update database with select control values

sskelton

Member
Joined
Sep 1, 2011
Messages
7
Programming Experience
10+
I want to duplicate Access's habit of saving selections in a form whenever a change is made but i am not clear on the syntax to send an UPDATE to the db when the selection changes. i hope this is easy to do and can be done 'generically' as i have a lot of controls and don't want to configure SelectedIndexChanged on each and every one...

I am using VS 2010/framework 4.0 and Sql Server CE.

Thanks in Advance!
 
If you want to do something on multiple events then you have no choice but to handle all those events. That said, you don't necessarily have to use separate event handlers for each. You can use the Properties window in the designer to create new and select existing event handlers. Just click the Events button to display events and the Properties button to display properties. Just as when working with properties, any changes you make to events effects all the currently selected components. If you select multiple ComboBoxes and double-click the SelectedIndexChanged event then a single event handler will be created for all of them. You could then select multiple TextBoxes and select that existing event handler for the TextChanged event. You now have one event handler to handle multiple ComboBox.SelectedIndexChanged and multiple TextBox.TextChanged events. This is the very reason that VB.NET doesn't support control arrays in the designer the way VB6 did.
 
what i'm not clear about is how to save selected items in the UI back to the database. I am using table adapters to fill datasets and i need to preserve any selections in the db. I am trying to figure out how to do this whenever a selection is made. The combo boxes generally are loaded from lookup tables and i set the value in the combo boxes when a tab panel is painted by reading the value from the source table from a label on the tab control panel.

if i can get the form to update the table to a new value, on re-paint i would expect to see the new value. but i am really confused as to how this is supposed to happen.

i understand one scenario is, a dataset is being modified and there's a method to update the entire dataset to the source table. there's another option to update a specific row (but you'd need to locate the row first). Or you could just go with commands and do SQL directly to the source table. I think I'd like to not do that, but i will if i have to.

To be specific, here's a dataset for a look-up use to bind to a combo box:

Me.LU_B4TableAdapter.Fill(Me._MyDatabase_1DataSet.LU_B4)

This is bound to the combo box using the Properties DataSource options.

In addition, there's a label on the form that is bound to the 'main' table i want to update:

Me.EditMDSTableAdapter.Fill(Me._MyDatabase_1DataSet.EditMDS, DLN:=DLN)

Label B4 is bound to this data source to the specific column and value based on a passed parameter. the Combo box is set to display the value from the label:

Me.ddUE_B4.SelectedValue = Me.B4.Text

Now, if i make a selection in the combo box am i not modifying the dataset of the combo box? If so, how do i send that change to the dataset EditMDS? This is where i am stuck.

I could just chuck all the dataset business and use SQL commands. That seems a bit odd as i am foregoing any advantages to datasets and table adapters, but it's something i can do. So, I dunno.
 
Back
Top