Connecting Tech Pros Worldwide Forums | Help | Site Map

I'm getting an error when I passed by ref a dataset to a new form

=?Utf-8?B?UHVjY2E=?=
Guest
 
Posts: n/a
#1: Jun 28 '07
Why am I getting an error when I passed by ref a dataset to a new form? The
message reads "cannot convert from 'ref Paimport.unixAccount' to 'ref
System.Data.DataSet'.
Paimport is the name of the form where the dataset UnixAccount is created.
I created the dataset using the designer tool and not by code. So it's like
a type or class which I then declare an instance of it :
UnixAccoutns dsAccounts = new UnixAccoutns ();

I pass to a new form in the construction as follow:
filterDlg = new frmFilter(ref dsAccounts, local, this);

How can I pass the entire dataset with all the datatables and the data in it
so I don't have to pass one table at a time? Thank you.
--
Thanks.

Jon Skeet [C# MVP]
Guest
 
Posts: n/a
#2: Jun 28 '07

re: I'm getting an error when I passed by ref a dataset to a new form


Pucca <Pucca@discussions.microsoft.comwrote:
Quote:
Why am I getting an error when I passed by ref a dataset to a new form? The
message reads "cannot convert from 'ref Paimport.unixAccount' to 'ref
System.Data.DataSet'.
Parameters passed by reference have to match type exactly.
Quote:
Paimport is the name of the form where the dataset UnixAccount is created.
I created the dataset using the designer tool and not by code. So it's like
a type or class which I then declare an instance of it :
UnixAccoutns dsAccounts = new UnixAccoutns ();
>
I pass to a new form in the construction as follow:
filterDlg = new frmFilter(ref dsAccounts, local, this);
>
How can I pass the entire dataset with all the datatables and the data in it
so I don't have to pass one table at a time? Thank you.
My guess is that you really don't need to pass it by reference at all.
Why do you think you do?
See http://pobox.com/~skeet/csharp/parameters.html

--
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
=?Utf-8?B?UHVjY2E=?=
Guest
 
Posts: n/a
#3: Jun 28 '07

re: I'm getting an error when I passed by ref a dataset to a new form


I thought I have to pass by ref so some of the tables in the dataset can have
new data insert to it. Is that not true? Thank you.
--
Thanks.


"Jon Skeet [C# MVP]" wrote:
Quote:
Pucca <Pucca@discussions.microsoft.comwrote:
Quote:
Why am I getting an error when I passed by ref a dataset to a new form? The
message reads "cannot convert from 'ref Paimport.unixAccount' to 'ref
System.Data.DataSet'.
>
Parameters passed by reference have to match type exactly.
>
Quote:
Paimport is the name of the form where the dataset UnixAccount is created.
I created the dataset using the designer tool and not by code. So it's like
a type or class which I then declare an instance of it :
UnixAccoutns dsAccounts = new UnixAccoutns ();

I pass to a new form in the construction as follow:
filterDlg = new frmFilter(ref dsAccounts, local, this);

How can I pass the entire dataset with all the datatables and the data in it
so I don't have to pass one table at a time? Thank you.
>
My guess is that you really don't need to pass it by reference at all.
Why do you think you do?
See http://pobox.com/~skeet/csharp/parameters.html
>
--
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
>
Peter Duniho
Guest
 
Posts: n/a
#4: Jun 28 '07

re: I'm getting an error when I passed by ref a dataset to a new form


On Thu, 28 Jun 2007 12:02:07 -0700, Pucca
<Pucca@discussions.microsoft.comwrote:
Quote:
I thought I have to pass by ref so some of the tables in the dataset can
have new data insert to it. Is that not true? Thank you.
That is not true.

You would have to pass as "ref" if you needed to modify the actual
reference to the instance. That is, you wanted to change the variable
from referencing one DataSet to referencing a different DataSet.

But if you simply want to modify the existing DataSet, passing the
reference by value is fine and in fact is what would normally be done.
See Jon's link for more details.

Pete
=?Utf-8?B?UHVjY2E=?=
Guest
 
Posts: n/a
#5: Jun 28 '07

re: I'm getting an error when I passed by ref a dataset to a new form


Yes, that does clear the error. And thank you for the link and the
explanation. Both were very helpful. That finally correct my wrong
understanding of ref type. Thank you both.
--
Thanks.


"Peter Duniho" wrote:
Quote:
On Thu, 28 Jun 2007 12:02:07 -0700, Pucca
<Pucca@discussions.microsoft.comwrote:
>
Quote:
I thought I have to pass by ref so some of the tables in the dataset can
have new data insert to it. Is that not true? Thank you.
>
That is not true.
>
You would have to pass as "ref" if you needed to modify the actual
reference to the instance. That is, you wanted to change the variable
from referencing one DataSet to referencing a different DataSet.
>
But if you simply want to modify the existing DataSet, passing the
reference by value is fine and in fact is what would normally be done.
See Jon's link for more details.
>
Pete
>
Closed Thread