We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now

x

How to pass a Dataset to a custom UserControl and back again to the parent, persisting changes.

Medium Priority
742 Views
Last Modified: 2012-05-11
Hello Experts:

I am using C#, VS 2010 and ADO.Net developing a data base application.

I am struggling with making changes to my dataset.

I populate the dataset from my SQL server db with a table adapter, to get my strongly type dataset we'll call myDataSet

I have a TabControl which acts as a container for a series of custom Usercontrols.

In the constructor of the myTabControl, I populate myDataset using a data access layer.  myDataSet is now populated and ready for consumption by the custom user controls.

When the user selects a tab, I Add() myCustomUserControl to the tabPage.

What I want to do is to pass myDataset to myCustomUserControl in some way so that the user can perform CRUD operations on the dataset in myUsercontrol and keep myDataSet in sync as changes are made.  Right now, I am using a new Table Adapter to update the BD from myUserControl but then I get unexpected behaviour on myDataSet when switching to another tab etc. - espicially when I perform Delete operations on the datarows in myUsercontrol dataset.   (DataRowNotInTable exceptions and myDataset not in sync.)

Is there a slick way of doing this??

Thanks
RW
Comment
Watch Question

Senior Developer
CERTIFIED EXPERT
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Author

Commented:
I am using the model you suggest - I pass the dataset to the constructor of myUsercontrol, but I get a RowNotInTable exception after i have deleted a row in myUserControl dataset  and have returned to another tab and try to access myDataset.

Commented:
i think you can close your dataset from tab1 because your user control on tab2 is using the same dataset as tab1 using.

Author

Commented:
Passing the dataset to the constructor of the child usercontrol works.  Keeping track of the state of the dataset is a challenge as I navigate the tabs of the tabcontrol and make changes to the dataset.

I suspect my model for handling the UI is not very sound.
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*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.