By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,449 Members | 1,601 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,449 IT Pros & Developers. It's quick & easy.

Link form DataSet to business layer DataSet, whilst maintaining design-time databinding support

P: n/a
I have a DataSet that bound to controls on multiple forms. Currently
an instance is created on each form and Load / Write is handled on
each form.

Instead I would like to have a single instance DataSet that is
accessed and maintained by Data Access Object (DAO) and I would like
that DataSet to be re-used on each form.

The problem I have is that when I drag a DataSet component onto a
form, I am having trouble linking it to the DataSet in the DAO class.

Dao class:

public class MantraXDao
{
private MantraXDao( )
{
m_dataSet = new MantraDataSet( );
m_dataSet.DataSetName = "MantraDataSet";
m_dataSet.Locale = new
System.Globalization.CultureInfo("en-AU");

Load( );
}

#region public interface

public void Load( )
{
m_dataSet.Clear( );
m_dataSet.ReadXml( "MantraX.xml" );
}

public void Write( )
{
m_dataSet.WriteXml( "MantraX.xml" );
}

#endregion

#region properties

public static MantraXDao Instance
{
get
{
if ( m_instance == null )
{
m_instance = new MantraXDao( );
}
return m_instance;
}
}

public MantraDataSet DataSet
{
get
{
return m_dataSet;
}
}

#endregion

#region fields

private static MantraXDao m_instance;

private MantraDataSet m_dataSet;

#endregion

}
// Calling conventions from each form
MantraXDao.Instance.Read // Refresh DataSet
MantraXDao.Instance.Write // Write DataSet
MantraXDao.Instance.DataSet // Obtain DataSet Instance

Cheers Dave
Nov 15 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Use Public Shared vaiable or Singleton method to access the same dataset to all form

Regard
Amal
Nov 15 '05 #2

P: n/a
D C
A singleton is essentially what I have done with this class already.
I've used a Factory pattern that only allows one instance of the DAO,
which wraps the DataSet.

The question is that I would like to drag that (SingleInstance) DataSet
into any form at designtype so that the DataBound properties on each
control can access the DataSet.

When you drag a DataSet onto a form, a wizard comes up that allows you
to select a previously created DataSet as a reference, but that wizard
won't allow me to get that reference from my DAO class.

Currently I have had to manually create the DataBinding:

private void InitDataSet( )
{
mantraDataSet = MantraXDao.Instance.DataSet;

dgMantra.DataSource = mantraDataSet;
dgMantra.DataMember = "Mt_Category.Mt_CategoryMt_Mantra";

dgCategory.DataSource = mantraDataSet;
dgCategory.DataMember = "Mt_Category";

cmbSkinType.DataBindings.Add(new Binding("SelectedItem",
mantraDataSet, "Mt_Config.SkinType"));
cmbSkinType.DataBindings.Add(new Binding("SelectedValue",
mantraDataSet, "Mt_Config.SkinType"));
cmbSkinType.DataBindings.Add(new Binding("Text", mantraDataSet,
"Mt_Config.SkinType"));

cmbAutoDisplay.DataBindings.Add(new Binding("SelectedItem",
mantraDataSet, "Mt_Config.AutoDisplay"));
cmbAutoDisplay.DataBindings.Add(new Binding("SelectedValue",
mantraDataSet, "Mt_Config.AutoDisplay"));
cmbAutoDisplay.DataBindings.Add(new Binding("Text",
mantraDataSet, "Mt_Config.AutoDisplay"));
}

Cheers Dave


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 15 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.