We help IT Professionals succeed at work.

Save datagrid back to dataset.

pdamson80
pdamson80 asked
on
473 Views
Last Modified: 2010-08-05
Hi, I have a windows form with a combo box and a datagrid. When I load the form, the datasets are generated and for each item in the combo box, there is a seperate dataset for each item in the combo box. The top value in the combo box is selected programatically and the coresponding dataset is displayed in the datagrid. Each time the user selects a different value in the combo box, the correct dataset is displayed in the datagrid. This all works fine.

I allow the user to edit one of the columns in the datagrid.  If the user selects a different value in the combo box, I want to save the new values into the original dataset so when the original value in the combo box is selected the changes are not lost.

Can anyone help me with this?

Thank you
Comment
Watch Question

Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
I have tried that, I put it in the combo box's click event, it doesn't update it.

Commented:
Are you reloading the datasets from the database in the Combo box's selected index changed event?

Commented:
One more issue to be kept in mind is, the changes made to a row in the datagrid is committed to the underlying datasource only when the cursor moves to the next "ROW"...

Author

Commented:
I am only getting the data from the database once. I am not adding rows to the datagrid, I am changing data in a column

Commented:
If you do the following , your problem will be solved.

1) in Constructor of your Forms After All DataSet Filled for the first time , write the following code for ALL table in ALL DataSet.

dset0.Tables["table1"].AcceptChange();
dset0.Tables["table2"].AcceptChange();
.
.
.
dset1.Tables["table1"].AcceptChange();
dset1.Tables["table2"].AcceptChange();
.
.
.
2)
Now suppose you have UpdateTables function to reflect the DataGrid Changes to DataSource :

UpdateTables()
{
 .....
 ......
 
 Call AcceptChanges Method just like in Constructor :

dset0.Tables["table1"].AcceptChange();
dset0.Tables["table2"].AcceptChange();
.
.

}
//------------------------------------------------

Commented:
Note that you should Call Update Method on your DataAdapters Before calling AcceptChanges Method.
 
 MOH_R

Commented:
can you post some code?

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.