How to pass a Dataset to a custom UserControl and back again to the parent, persisting changes.
Posted on 2011-04-28
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??