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

Passing Dataset to another WinForm

P: n/a
JJ
Hi,

I need to pass a dataset to another win form along with a SqldataAdapter.
I don't want to recreate the SqlDataAdapter again either. So to pass to
another Win form in my windows form app, do I create the procedure to pass by
ref? Which means I don't need to add ByRef because it is defaulted by ref,
correct? And in the constructor of the win form that gets created. I need to
add in parameters a DataSet and SqlDataAdapter correct? What is the standard
way of passing datasets around window forms?

Thanks,

JJ
Nov 17 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a

On your destination form you need to have a DataSet variable which
references a DataSet object. From here you need to provide a public property
that allows you to set and get the object reference by this variable. Once
this is complete, the source form which contains the DataSet to use creates
the new form, then assigns the dataset to the property. You can then utilise
this DataSet in the new form in the load event.

Your code would look something like this...

// destination form

private DataSet _myDS;
public DataSet MyDS
{
get
{
return _myDS;
}
set
{
// does not create a new dataset,
// but gives the variable a reference to
// the dataset assigned to MyDS
_myDS = value;
}
}
// source form (before displaying/creating the new form)
// - code assumes you have your dataset ready

destForm = new Form();
destForm.MyDS = readyDataSet;
destForm.ShowDialog();

Hope that helps.
Dan.


"JJ" <JJ@discussions.microsoft.com> wrote in message
news:BF**********************************@microsof t.com...
Hi,

I need to pass a dataset to another win form along with a
SqldataAdapter.
I don't want to recreate the SqlDataAdapter again either. So to pass to
another Win form in my windows form app, do I create the procedure to pass
by
ref? Which means I don't need to add ByRef because it is defaulted by ref,
correct? And in the constructor of the win form that gets created. I need
to
add in parameters a DataSet and SqlDataAdapter correct? What is the
standard
way of passing datasets around window forms?

Thanks,

JJ

Nov 17 '05 #2

P: n/a
JJ
Hi Dan,

On the destination form I created in the constructor a parameter to
accept a dataset instead. Then in constructor I copy dataset to private
dataset variable like so:

private DataSet dsNew;

DstForm(DataSet ds)
{
dsNew = ds.Copy();
}

Wouldn't this work too?

Thanks,

JJ

"Dan Bass" wrote:

On your destination form you need to have a DataSet variable which
references a DataSet object. From here you need to provide a public property
that allows you to set and get the object reference by this variable. Once
this is complete, the source form which contains the DataSet to use creates
the new form, then assigns the dataset to the property. You can then utilise
this DataSet in the new form in the load event.

Your code would look something like this...

// destination form

private DataSet _myDS;
public DataSet MyDS
{
get
{
return _myDS;
}
set
{
// does not create a new dataset,
// but gives the variable a reference to
// the dataset assigned to MyDS
_myDS = value;
}
}
// source form (before displaying/creating the new form)
// - code assumes you have your dataset ready

destForm = new Form();
destForm.MyDS = readyDataSet;
destForm.ShowDialog();

Hope that helps.
Dan.


"JJ" <JJ@discussions.microsoft.com> wrote in message
news:BF**********************************@microsof t.com...
Hi,

I need to pass a dataset to another win form along with a
SqldataAdapter.
I don't want to recreate the SqlDataAdapter again either. So to pass to
another Win form in my windows form app, do I create the procedure to pass
by
ref? Which means I don't need to add ByRef because it is defaulted by ref,
correct? And in the constructor of the win form that gets created. I need
to
add in parameters a DataSet and SqlDataAdapter correct? What is the
standard
way of passing datasets around window forms?

Thanks,

JJ


Nov 17 '05 #3

P: n/a
JJ,

This would work, but it depends on what you want to do. Creating a copy
means any changes made to the dataset stay within the form... If you just
say "dsNew = ds; " then the reference to the object is passed through, and
your second form is utilising the orginal object.

So it depends on what your requirements are.

Dan.

"JJ" <JJ@discussions.microsoft.com> wrote in message
news:1F**********************************@microsof t.com...
Hi Dan,

On the destination form I created in the constructor a parameter to
accept a dataset instead. Then in constructor I copy dataset to private
dataset variable like so:

private DataSet dsNew;

DstForm(DataSet ds)
{
dsNew = ds.Copy();
}

Wouldn't this work too?

Thanks,

JJ

"Dan Bass" wrote:

On your destination form you need to have a DataSet variable which
references a DataSet object. From here you need to provide a public
property
that allows you to set and get the object reference by this variable.
Once
this is complete, the source form which contains the DataSet to use
creates
the new form, then assigns the dataset to the property. You can then
utilise
this DataSet in the new form in the load event.

Your code would look something like this...

// destination form

private DataSet _myDS;
public DataSet MyDS
{
get
{
return _myDS;
}
set
{
// does not create a new dataset,
// but gives the variable a reference to
// the dataset assigned to MyDS
_myDS = value;
}
}
// source form (before displaying/creating the new form)
// - code assumes you have your dataset ready

destForm = new Form();
destForm.MyDS = readyDataSet;
destForm.ShowDialog();

Hope that helps.
Dan.


"JJ" <JJ@discussions.microsoft.com> wrote in message
news:BF**********************************@microsof t.com...
> Hi,
>
> I need to pass a dataset to another win form along with a
> SqldataAdapter.
> I don't want to recreate the SqlDataAdapter again either. So to pass to
> another Win form in my windows form app, do I create the procedure to
> pass
> by
> ref? Which means I don't need to add ByRef because it is defaulted by
> ref,
> correct? And in the constructor of the win form that gets created. I
> need
> to
> add in parameters a DataSet and SqlDataAdapter correct? What is the
> standard
> way of passing datasets around window forms?
>
> Thanks,
>
> JJ


Nov 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.