Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / ADO.NET / December 2006

Tip: Looking for answers? Try searching our database.

Strongly typed datased (it's datatable) as singleton

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jirí Neuzil - 28 Dec 2006 15:04 GMT
Hi,
I have problem with implementing strongly typed dataset (with tableadapter)
as singleton (A very large amount of data loaded at startup of winforms app,
I need this data at numbers of forms, and I need to bind this
dataset/datatable at designtime) . At first I realized implementing dataset
as singleton cause problems in design time. So I decided to implement
dataset's datatable as singleton.

Here is my code (dsSuau is strongly typed dataset):

partial class dsSuau
   {
        partial class TabSuauDataTable
       {
           private static TabSuauDataTable _tabSuauDataTable;

           public static TabSuauDataTable getInstance()
           {
               if (TabSuauDataTable._tabSuauDataTable == null)
               {
                   _tabSuauDataTable = new TabSuauDataTable();
               }
               return _tabSuauDataTable;
           }

             public void Fill()
            {
                dsSuauTableAdapters.TabSuauTableAdapter _tableAdapter = new
ageu.DataLayer.dsSuauTableAdapters.TabSuauTableAdapter();
                _tableAdapter.Fill(_tabSuauDataTable);
            }
       }
   }

Then I changed constructor visibility of TabSuauDataTable in designer.cs
file to private and changed some of dataset's method in designer.cs:

[System.Diagnostics.DebuggerNonUserCodeAttribute()]
       private void InitClass()
       {
           this.DataSetName = "dsSuau";
           this.Prefix = "";
           this.Namespace = "http://tempuri.org/dsSuau.xsd";
           this.EnforceConstraints = true;
           this.SchemaSerializationMode =
System.Data.SchemaSerializationMode.IncludeSchema;
           //zmena
           this.tableTabSuau =
ageu.DataLayer.dsSuau.TabSuauDataTable.getInstance();
           if (this.tableTabSuau.DataSet != null)
           {
                       this.tableTabSuau.DataSet.Tables.Clear();
           }
           base.Tables.Add(this.tableTabSuau);
       }

This solution works, only one instance of datatable is created at startup of
application and is migrating throught forms and datasets.
But I have problem with VS 2005 designer. If I change dataset in design time
(add column to datatable for example), designer.cs file is overwritten and
my changes are lost. Are there any other ways to implement this singleton
behavior with desing time databinding to form, or some possibility to mark
my changed methods in designer.cs to prevent VS 2005 to overwrite them?

Thank you in advace
Jesús López - 29 Dec 2006 12:21 GMT
You can define a specific dataview in such a way that every instance of this
dataview points to the singleton datatable instance. You use an instance of
the dataview to databind to windows controls at design time:

public class SuauDataView : DataView
{
   public SuauDataView()
   {
       this.Table = dsSuau.TabSuauDataTable.getInstance();
   }

}

Regards:

Jesús López

> Hi,
> I have problem with implementing strongly typed dataset (with
[quoted text clipped - 62 lines]
>
> Thank you in advace

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.