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

shared Dataset

P: n/a
I have seen some posts on this subject but I still cannot make my app work right.

I have a MDI application with a parent form and two child forms.
The parent form is called Mainform
The child forms are called invoiceForm and customerForm

I have a dataset containing customer info which I would like to make available to all forms.
The dataset is called dsCustomers

So in my parent form code in the general declarations area I have this
Expand|Select|Wrap|Line Numbers
  1. Public Shared WithEvents DSCust As New InvoiceWhiz.dsCustomers
  2. Public custForm As New customerForm
  3. Public invForm as new invoiceForm
  4.  
I open each form from MainForm like this
[code]
invForm.MdiParent = Me
custForm.MdiParent = Me
invForm.Show()
custForm.show()
[\code]

I reference the dataset from the children like this

[code]

datagrid.datasource = Mainform.DSCust.customer

[\code]

All of this builds with no errors and runs fine at first then VS gives an error like this

C:\Documents and Settings\Administrator\My Documents\Visual Studio Projects\InvoiceWhiz\customerForm.vb(70): The variable 'DSCust' is either undeclared or was never assigned.

And then erases my reference in the child code.

Cany anyone help me out on this?
Thanks,
Kratz


From http://www.developmentnow.com/g/38_0_0_0_0_0/dotnet-languages-vb.htm

Posted via DevelopmentNow.com Groups
http://www.developmentnow.com
Nov 21 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a

well instead of making it public availlable you could probably better pass
it to the other form as a parameter if the data is required for he life of
the object you could pass it in the constructor

regards

Michel Posseth


"kratz" <kr***@koyote.com> wrote in message
news:06**********************************@msnews.m icrosoft.com...
I have seen some posts on this subject but I still cannot make my app work
right.

I have a MDI application with a parent form and two child forms.
The parent form is called Mainform
The child forms are called invoiceForm and customerForm

I have a dataset containing customer info which I would like to make
available to all forms.
The dataset is called dsCustomers

So in my parent form code in the general declarations area I have this
Expand|Select|Wrap|Line Numbers
  1.     Public Shared WithEvents DSCust As New InvoiceWhiz.dsCustomers
  2.     Public custForm As New customerForm
  3.     Public invForm as new invoiceForm
  4.  

I open each form from MainForm like this
[code]
invForm.MdiParent = Me
custForm.MdiParent = Me
invForm.Show()
custForm.show()
[\code]

I reference the dataset from the children like this

[code]

datagrid.datasource = Mainform.DSCust.customer

[\code]

All of this builds with no errors and runs fine at first then VS gives an
error like this

C:\Documents and Settings\Administrator\My Documents\Visual Studio
Projects\InvoiceWhiz\customerForm.vb(70): The variable 'DSCust' is either
undeclared or was never assigned.

And then erases my reference in the child code.

Cany anyone help me out on this?
Thanks,
Kratz


From http://www.developmentnow.com/g/38_0_0_0_0_0/dotnet-languages-vb.htm

Posted via DevelopmentNow.com Groups
http://www.developmentnow.com

Nov 21 '05 #2

P: n/a
Hi Kratz,

I am going to give the best help that 'I' can! It may not answer your
question(s) but I guess it should work. Maybe others with more db knowledge
will post something more descriptive.

I am not sure how you actually get your data into the dataset, whether you
code the connection perhaps and use the Fill method of the dataadapter, or
whether you are dragging connection components onto your form from within
the IDE.

Not sure why you use WithEvents. Datasets only have one event which is
MergeFailed (other than dispose!). Perhaps you are using this!!

I would probably do something like

(MainForm)

Public dsMain as New Dataset
(MainForm Load Event)

'Declare and instantiate data components
da.Fill(dsMain, "Results")

(mdiForms)

dgMdi.DataSource = MainForm.dsMain
dgMdi.DataMember = "Results"

HTH, Phil
"kratz" <kr***@koyote.com> wrote in message
news:06**********************************@msnews.m icrosoft.com...
I have seen some posts on this subject but I still cannot make my app work
right.

I have a MDI application with a parent form and two child forms.
The parent form is called Mainform
The child forms are called invoiceForm and customerForm

I have a dataset containing customer info which I would like to make
available to all forms.
The dataset is called dsCustomers

So in my parent form code in the general declarations area I have this
Expand|Select|Wrap|Line Numbers
  1.     Public Shared WithEvents DSCust As New InvoiceWhiz.dsCustomers
  2.     Public custForm As New customerForm
  3.     Public invForm as new invoiceForm
  4.  

I open each form from MainForm like this
[code]
invForm.MdiParent = Me
custForm.MdiParent = Me
invForm.Show()
custForm.show()
[\code]

I reference the dataset from the children like this

[code]

datagrid.datasource = Mainform.DSCust.customer

[\code]

All of this builds with no errors and runs fine at first then VS gives an
error like this

C:\Documents and Settings\Administrator\My Documents\Visual Studio
Projects\InvoiceWhiz\customerForm.vb(70): The variable 'DSCust' is either
undeclared or was never assigned.

And then erases my reference in the child code.

Cany anyone help me out on this?
Thanks,
Kratz


From http://www.developmentnow.com/g/38_0_0_0_0_0/dotnet-languages-vb.htm

Posted via DevelopmentNow.com Groups
http://www.developmentnow.com

Nov 21 '05 #3

P: n/a
Just a suggestion but I would create a class for my database procedures and
set up properties and methods for setting and returning data from/to my
database and/or dataset. I think you will find this a lot easier to keep up
your database/dataset iaccess procedures if they are in one class. You can
instantiate this class in your mainform and access it
"MainForm.myDBClass.myProperty or make it global.

--
Dennis in Houston
"kratz" wrote:
I have seen some posts on this subject but I still cannot make my app work right.

I have a MDI application with a parent form and two child forms.
The parent form is called Mainform
The child forms are called invoiceForm and customerForm

I have a dataset containing customer info which I would like to make available to all forms.
The dataset is called dsCustomers

So in my parent form code in the general declarations area I have this
Expand|Select|Wrap|Line Numbers
  1.      Public Shared WithEvents DSCust As New InvoiceWhiz.dsCustomers
  2.      Public custForm As New customerForm
  3.      Public invForm as new invoiceForm
  4.  

I open each form from MainForm like this
[code]
invForm.MdiParent = Me
custForm.MdiParent = Me
invForm.Show()
custForm.show()
[\code]

I reference the dataset from the children like this

[code]

datagrid.datasource = Mainform.DSCust.customer

[\code]

All of this builds with no errors and runs fine at first then VS gives an error like this

C:\Documents and Settings\Administrator\My Documents\Visual Studio Projects\InvoiceWhiz\customerForm.vb(70): The variable 'DSCust' is either undeclared or was never assigned.

And then erases my reference in the child code.

Cany anyone help me out on this?
Thanks,
Kratz


From http://www.developmentnow.com/g/38_0_0_0_0_0/dotnet-languages-vb.htm

Posted via DevelopmentNow.com Groups
http://www.developmentnow.com

Nov 21 '05 #4

P: n/a
Thanks to all for the suggestions. I decided to try Michel's suggestions
first. So in my ParentForm code I have

Private DSCust As New xxxxx.dsCustomers
Public custForm As New customerForm(DSCust)
Public invForm As New invoiceform(DSCust)

in the general declarations area.

Then in each childForm code I have

Public Sub New(ByRef DsCust As xxxxx.dsCustomers)

but when I try to reference the dataset in child code like this

datagrid.datasource = DsCust.customer

I get errors saying "Name 'DsCust' is not declared"

What am I doing wrong?
Thanks again,
Kratz

--
Sent via .NET Newsgroups
http://www.dotnetnewsgroups.com
Nov 21 '05 #5

P: n/a
well i would go for an aproach like this

Public Class clsMain
Private dsMain As New DataSet
Friend Sub justamethod()
Dim cchild As New ClsChild(dsMain)
cchild.PerformActionsOnDS()
dsMain = cchild.dsRet
End Sub
End Class

Friend Class ClsChild
Private _ds As DataSet
Friend ReadOnly Property dsRet() As DataSet
Get
Return _ds
End Get
End Property
Friend Sub New(ByVal ds As DataSet)
_ds = ds
End Sub
Friend Sub PerformActionsOnDS()
'poerform you actions on the dataset
End Sub
End Class
clschild can "live" on its own when the required dataset is passed
"kratz" wrote:
Thanks to all for the suggestions. I decided to try Michel's suggestions
first. So in my ParentForm code I have

Private DSCust As New xxxxx.dsCustomers
Public custForm As New customerForm(DSCust)
Public invForm As New invoiceform(DSCust)

in the general declarations area.

Then in each childForm code I have

Public Sub New(ByRef DsCust As xxxxx.dsCustomers)

but when I try to reference the dataset in child code like this

datagrid.datasource = DsCust.customer

I get errors saying "Name 'DsCust' is not declared"

What am I doing wrong?
Thanks again,
Kratz

--
Sent via .NET Newsgroups
http://www.dotnetnewsgroups.com

Nov 21 '05 #6

P: n/a
Michel thanks so much for the help. I got it working. I still have one
question though. When you have a property like this
Public class2
Public Property ds as TypedDataset
Get
Set
End Property

If you set the property from another class like

class2.ds = me.datasetWithData

does it just do a copy of the structure of the dataset and leave out the
data?

thanks again,
Kratz

--
Sent via .NET Newsgroups
http://www.dotnetnewsgroups.com
Nov 21 '05 #7

P: n/a
it will copy the hole dataset inclusive the data

regards

Michel posseth
"kratz" wrote:
Michel thanks so much for the help. I got it working. I still have one
question though. When you have a property like this
Public class2
Public Property ds as TypedDataset
Get
Set
End Property

If you set the property from another class like

class2.ds = me.datasetWithData

does it just do a copy of the structure of the dataset and leave out the
data?

thanks again,
Kratz

--
Sent via .NET Newsgroups
http://www.dotnetnewsgroups.com

Nov 21 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.