473,624 Members | 2,290 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.unixAc count' to 'ref
System.Data.Dat aSet'.
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 1475
Pucca <Pu***@discussi ons.microsoft.c omwrote:
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.unixAc count' to 'ref
System.Data.Dat aSet'.
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.co m>
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***@discussi ons.microsoft.c omwrote:
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.unixAc count' to 'ref
System.Data.Dat aSet'.

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.co m>
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***@discussi ons.microsoft.c omwrote:
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***@discussi ons.microsoft.c omwrote:
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
2393
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 will be returned as DataSet. Now, here's the problem. On .NET Framework 1.1, if any rows in the dataset returned contain errors (marked by calling the SetColumnError() method or
6
3181
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 name 'CoreLab' could not be found (are you missing a using directive or an assembly reference?)" I downloaded the add on for connecting to MySQL using ADO.NET and installed it, but am still getting this error. Anybody ever run into this before?
4
1784
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 you. ====================================== Private Sub SaveChanges(ByVal aContainer As Object)
13
10123
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 parent table. ----------------------------
1
2176
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 table names that are in the XML file, but I'm not able to access the rows. Here's the code that I've got - it assumes that the fileName passed in already exists: Public Sub GetInput(ByVal fileName As String) dsFileCopy = New...
7
4088
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 btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click 'If imageDataSet.HasChanges Then _databaseMethods.ProcessUpdates(imageDataSet) 'End If
5
1942
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. -------------------------------------------------------------------------------- The text, ntext, and image data types cannot be compared or sorted, except when using IS NULL or LIKE operator. Description: An unhandled exception occurred during the execution of the current web request....
0
1336
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 error message. I need help with the format of the SQLAdapter.Update(DSet.Tables(0)) command. I have included my code below. The line is in bold text. Imports System Imports System.Reflection Imports System.Text Imports System.Collections...
2
1881
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 following in C# This is the method I am calling, which populates ref paramters with results. Sub Check_Customer(ByVal Customer As String, Optional ByRef oParam1 As
0
8242
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8177
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8341
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8488
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6112
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4084
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4183
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1793
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1488
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.