473,498 Members | 1,557 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

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.
Jun 28 '07 #1
4 1462
Pucca <Pu***@discussions.microsoft.comwrote:
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.
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 - <sk***@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
Jun 28 '07 #2
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:
Pucca <Pu***@discussions.microsoft.comwrote:
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.
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 - <sk***@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
Jun 28 '07 #3
On Thu, 28 Jun 2007 12:02:07 -0700, Pucca
<Pu***@discussions.microsoft.comwrote:
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
Jun 28 '07 #4
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:
On Thu, 28 Jun 2007 12:02:07 -0700, Pucca
<Pu***@discussions.microsoft.comwrote:
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
Jun 28 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
2370
by: Programatix | last post by:
Hi, I'm working on a project which includes XML WebServices and Windows Form application. The Windows Form application will call the XML WebServices to retrieve data from database. The data...
6
3172
by: Erik H. | last post by:
Trying to connect to MySQL db on localhost, and populate datagrid from a dataset using code inline method. Getting the following compile error: Error Message: "CS0246: The type or namespace...
4
1773
by: astro | last post by:
I would like to build some generic code that is able to figure out the correct dataAdapter to apply changes to given a form with several dataAdapters. Any suggestions on the following? Thank...
13
10085
by: dbuchanan | last post by:
Hello, Here is the error message; ---------------------------- Exception Message: ForeignKeyConstraint Lkp_tbl040Cmpt_lkp302SensorType requires the child key values (5) to exist in the...
1
2167
by: hzgt9b | last post by:
(FYI, using VB .NET 2003) Can someone help me with this... I'm trying to read in an XML file... it appears to work in that the DataSet ReadXML method dose not fail and then I am able to access the...
7
4080
by: darjonase | last post by:
I am having a problem, and I wonder if anyone could help me with it. I have two methods. The first on a form calls the second method which is located in a class lib. 'Form Method Private Sub...
5
1932
by: Mr. SweatyFinger | last post by:
WHY CAN'T THE CLOWN -HOLES WHO WROTE ASP.NET PROVIDE AN ERROR LINE NUMBER??? HONEST TO SH@THOLE PETE Server Error in '/New Folder (7)' Application....
0
1333
by: JimN1 | last post by:
Error: Update requires a valid UpdateCommand when passed DataRow collection with modified rows. This is a continuation of my previous table element update question. I am now getting the above...
2
1871
by: rocketfire97 | last post by:
I'm trying to call a COM object using C# but having no luck getting values back for passed in ref objects. I've tried the same call using VB.NET and can get data back. How would I implement the...
0
7126
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7005
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7210
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6891
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7381
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5465
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4595
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3096
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
1
659
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.