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

M

muesliflakes

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
 
G

Guest

Use Public Shared vaiable or Singleton method to access the same dataset to all form

Regard
Amal
 
D

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top