?
Solved

How to Use a Global Typed Dataset (VB.NET 2005 WinForms)

Posted on 2009-04-19
9
Medium Priority
?
630 Views
Last Modified: 2012-05-06
I am missing something important here.  I need a global typed DataSet that I can fill, and then use it for Grids and Crystal Reports on other forms. I seems to make sense to instantiate the DataSet objects in the Load of a Parent form (when users are in this part of the app).  The psuedo code shows my basic approach, but something is wrong (some spelling might be off).

Any assistance and understanding appeciated.

In Project Dataset:
   DsResults (DataSet)
   dt_Results  (typed DataTable)
   dt_ResultsTableAdapter (TableAdapter)
   dt_ResultsTableAdapter.FillResults(<datatable>, <parmWhere>)
 
Public Class clsLookup  (also tried making these Shared)
    Public dsLookup As DsResults
    Public DT_Results As DsResults.dt_Results
    Public DT_ResultsTableAdapter As DsResultsTableAdapters.dt_ResultsTableAdapter
 
Public Class clsGlobal
    Public Shared gobjgLookup As clsLookup
    Public Sub New()
    End Sub
 
USAGE: (parent form Load)
Imports App2.clsGlobal
Imports App2.clsLookup
clsGlobal.gobjLookup = New clsLookup
 
USAGE: (user initiated lookup)
Imports App2.clsLookup
Imports App2.clsGlobal
clsGlobal.gobjResults.DT_ResultsTableAdapter.FillResults(clsGlobal.gobjResults.DT_Results, strWhere)
(ERROR: Object reference not set to instance of an object)

Open in new window

0
Comment
Question by:cgaDesign
  • 6
  • 3
9 Comments
 
LVL 11

Accepted Solution

by:
anyoneis earned 1000 total points
ID: 24180068
cgaDesign;

RE: "clsGlobal.gobjResults.DT_Results"

I think you simplified too much, since clsGlobal does not have a gobjResults property. In any case, where has you created an instance of clsGlobal?

David

0
 
LVL 11

Expert Comment

by:anyoneis
ID: 24180070
Why does my keybroad do that!?!?

"has you created an instance" s/b "have you created an instance"
0
 

Author Comment

by:cgaDesign
ID: 24180130
Re: where is instance of clsGlobal created ... I could not find it so far ... I have been using the "class" for global variable, and since they are declared as Shared, I don't think I needed an instance of clsGlobat.  So maybe this is part of the problem for my new global variable: gobjResults.  In general, do you think I am approaching the global dataset issue in a reasonable manner?
Thank you, Steve
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 11

Assisted Solution

by:anyoneis
anyoneis earned 1000 total points
ID: 24180271
Steve;

I think you are close, but perhaps what you want is a shared default constructor. This will be run the first timje the Class is referenced. In that constructor, you can initialize a shared property with the reference to the dataset.

Then, when you reference ClassName.PropertyName for the first time, the static (shared) class constructor is run, and it initializes the property with an instance of yourtyped fdataset. Then the property accessor is run, delivering it up to you.

David
0
 
LVL 11

Assisted Solution

by:anyoneis
anyoneis earned 1000 total points
ID: 24180378
Here is an example VB Console program:
Module Module1
 
    Class gblMyClass
 
        Private Shared propMyProperty As String
 
        Public Shared ReadOnly Property MyProperty()
            Get
                Console.WriteLine("MyProperty accessor being called")
                Return propMyProperty
            End Get
        End Property
        Shared Sub New()
            Console.WriteLine("Shared ctor being called")
            propMyProperty = "Global data"
        End Sub
 
    End Class
    Sub Main()
        Console.WriteLine("Main beginning called")
        Console.WriteLine("Shared global object value is: '{0}'", gblMyClass.MyProperty)
        Console.WriteLine("Main ending")
    End Sub
 
End Module

Open in new window

0
 
LVL 11

Expert Comment

by:anyoneis
ID: 24180389
Resulting in:

Main beginning called
Shared ctor being called
MyProperty accessor being called
Shared global object value is: 'Global data'
Main ending


0
 

Author Comment

by:cgaDesign
ID: 24180435
Your first hint helped ...
1.  I am now only using clsLookup to hold my Public DataSet objects. I instantiate the DataSet, DataTable and TableAdapter objects in a Parent form (but I might as well move these to the Sub New, as you are suggesting).  I actually don't think I need the DataTable object, as it is usually referenced thru the DataSet obj.  I am now filling my DataGridViews with this scenario.

2.  I now need to hook up the Global DataSet to my Crystal Reports ... which I think I can do ... just set the Report DataSource at Runtime.  (But I don't want to loose the DesignTime DataSource).

3.  STILL A PROBLEM:  I set a Tag field in the Global DataTable via a DataGridView (via a BindingSource).  I need the Reports to use this Global DataTable, but not to print rows that are NOT TAGGED.  Maybe this is for a separate post ... but is there a way to Filter a DataTable so the a Report uses the Filter, or so that the Report doesn't see the un-Tagged rows ?

Thank you again ...

0
 
LVL 11

Assisted Solution

by:anyoneis
anyoneis earned 1000 total points
ID: 24180481
I'm not knowledgeable about Crystal Reports. But, when I need to filter the results in a table, I usually do something like:

dtMyTable.DefaultView.RowFilter = "Tag = 0"

David
0
 

Author Closing Comment

by:cgaDesign
ID: 31571991
David, thanks very much for all the useful thoughts, which solved my problem.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses

755 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question