473,626 Members | 3,298 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Assignment Method

Seems like there ought to be a method that copies an object. If I do
something like this:

System.Data.Odb c.OdbcCommand cmd;
cmd = new OdbcCommand();
cmd.Connection = odbc_Categories ;
cmd.CommandText = "SELECT * FROM \"tblCategor y\" ORDER BY \"Category\" ";
odbcDA_CatSubCa ts.SelectComman d = cmd;

All is well. But if I want to use cmd again, say for the Update command by
redefining the CommandText property and then doing this:

odbcDA_CatSubCa ts.UpdateComman d = cmd;

I would redefine the SelectCommand as well. I would like to copy the
property values of the cmd object to the various Command objects of the DA.

I thought that MemberwiseClone () might handle this, but when I try this:

odbcDA_CatSubCa ts.UpdateComman d = (OdbcCommand)cm d.MemberwiseClo ne();

I get this:

Cannot access protected member 'object.Memberw iseClone()' via a qualifier
of type 'OdbcCommand'; the qualifier must be of type 'frmCategories' (or
derived from it)

'frmCategories' is the name of the form's class within which I'm working.

Is this because OdbcCommand is not derived from Object? Is there a way to
get around this? I'm thinking that a little refactoring might do the trick,
but I would like to know if there is an assignment method (or copy method)
for this object class.
Nov 17 '05 #1
6 1733
My immediate reaction was simply to call cmd.Clone(), because the doc
says that OdbcCommand implements ICloneable. Only that... it doesn't!
The doc is lying.

Nov 17 '05 #2
Bruce Wood <br*******@cana da.com> wrote:
My immediate reaction was simply to call cmd.Clone(), because the doc
says that OdbcCommand implements ICloneable. Only that... it doesn't!
The doc is lying.


No it's not. It implements it with explicit interface implementation.
Try the following:

using System;
using System.Data.Odb c;

class Test
{
static void Main()
{
OdbcConnection conn = new OdbcConnection( );

OdbcConnection conn2 = (OdbcConnection )
((ICloneable)co nn).Clone();
}
}

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 17 '05 #3
Excellent. I applied this to the OdbcCommand class and it worked fine.

Thanks.
"Jon Skeet [C# MVP]" <sk***@pobox.co m> wrote in message
news:MP******** *************** *@msnews.micros oft.com...
Bruce Wood <br*******@cana da.com> wrote:
My immediate reaction was simply to call cmd.Clone(), because the doc
says that OdbcCommand implements ICloneable. Only that... it doesn't!
The doc is lying.


No it's not. It implements it with explicit interface implementation.
Try the following:

using System;
using System.Data.Odb c;

class Test
{
static void Main()
{
OdbcConnection conn = new OdbcConnection( );

OdbcConnection conn2 = (OdbcConnection )
((ICloneable)co nn).Clone();
}
}

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 17 '05 #4

"Jon Skeet [C# MVP]" <sk***@pobox.co m> wrote in message
news:MP******** *************** *@msnews.micros oft.com...
Bruce Wood <br*******@cana da.com> wrote:
My immediate reaction was simply to call cmd.Clone(), because the doc
says that OdbcCommand implements ICloneable. Only that... it doesn't!
The doc is lying.


No it's not. It implements it with explicit interface implementation.
Try the following:

using System;
using System.Data.Odb c;

class Test
{
static void Main()
{
OdbcConnection conn = new OdbcConnection( );

OdbcConnection conn2 = (OdbcConnection )
((ICloneable)co nn).Clone();
}
}


How does that help, btw? They are talking about the OdbcCommand, not
OdbcConnection :P I haven't checked myself to see if OdbcCommand does in
fact implement it, but just pointing it out which object they are referring
to :)

Mythran

Nov 17 '05 #5
Mythran <ki********@hot mail.comREMOVET RAIL> wrote:
How does that help, btw? They are talking about the OdbcCommand, not
OdbcConnection :P I haven't checked myself to see if OdbcCommand does in
fact implement it, but just pointing it out which object they are referring
to :)


Oops - good catch.

The same goes for OdbcCommand, fortunately :)

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 17 '05 #6

"Jon Skeet [C# MVP]" <sk***@pobox.co m> wrote in message
news:MP******** *************** *@msnews.micros oft.com...
Mythran <ki********@hot mail.comREMOVET RAIL> wrote:
How does that help, btw? They are talking about the OdbcCommand, not
OdbcConnection :P I haven't checked myself to see if OdbcCommand does in
fact implement it, but just pointing it out which object they are
referring
to :)


Oops - good catch.

The same goes for OdbcCommand, fortunately :)

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too


lol, I noticed a bit after I posted the message that your message helped
them solve the problem, so all is good :)

Mythran

Nov 17 '05 #7

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

Similar topics

5
4826
by: CoolPint | last post by:
It seems to me that I cannot assign objects of a class which has a constant data member since the data member cannot be changed once the constructor calls are completed. Is this the way it is meant to be? Am I not suppose not to have any constant data member if I am going to have the assignment operator working for the class? Or am I missing something here and there is something I need to learn about? Clear, easy to understand...
16
2596
by: Edward Diener | last post by:
Is there a way to override the default processing of the assignment operator for one's own __value types ? I realize I can program my own Assign method, and provide that for end-users of my class, but I would like to use internally my own = operator for some of my value types, so I can say "x = y;" rather than "x.Assign(y);". The op_Assign operator seems impossibly broken since it takes __value copies of the two objects. Perhaps there is...
9
462
by: August1 | last post by:
Below are the declaration for an overloaded assignment operator in an interface file in addition to the implementation file definition of the function. What would be an appropriate if condition to ensure that a client of the program cannot assign an object of the class to itself. The if() condition would be placed within the function definition to compare the operand in the function parameter is not the same as the temporary object being...
7
3908
by: Mr. Ed | last post by:
I have a base class which has about 150 derived classes. Most of the derived classes are very similar, and many don't change the base class at all. All the derived classes have a unique factory method which returns a new object of the derived type. The problem I've got is that I now need to polymorphically clone a derived class object, but I don't want to write a separate 'clone' method for each of these 150 classes. Instead, I thought I...
7
4665
by: Sean | last post by:
Can someone help me see why the following "operator=" overloading doesn't work under g++? and the error message is copied here. I see no reason the compiler complain this. Thanks, $ g++ copyconstructor1.cpp #copyconstructor1.cpp: In function `int main()': #copyconstructor1.cpp:86: no match for `sample& = sample' operator #copyconstructor1.cpp:53: candidates are: sample sample::operator=(sample&) ...
2
2758
by: Chad | last post by:
I'm in an intro to VB.net class. I'm haveing trouble with this assignment, if anyone could help me please let me know. thanks! Coding Assignment 7-Chapter 8 OOP-CSCI-171 Intro to VB.NET 1. Create a Windows application that models a carton of eggs: Define a public class and call it cEggCarton to model the egg carton. Declare a module-scope object variable of type cEggCarton. Since we want the object to persist throughout the life...
9
3492
by: sturlamolden | last post by:
Python allows the binding behaviour to be defined for descriptors, using the __set__ and __get__ methods. I think it would be a major advantage if this could be generalized to any object, by allowing the assignment operator (=) to be overloaded. One particular use for this would be to implement "lazy evaluation". For example it would allow us to get rid of all the temporary arrays produced by NumPy. For example, consider the...
11
2496
by: markryde | last post by:
Hello, Followed here is a simplified code example of something which I try to implement; in essence , I want to assign a value to a return value of a method is C. I know, of course, that in this example I can get this by newskb->iph = iphdr (this also appears in a commented line in the example below) ; but I want to achieve the same where the left side is : ip_hdr(newskb). Alas, if I try this , I get a compilation error about line 25....
5
2679
by: mangoxoxo | last post by:
Hey I'm not sure if this is where I should be asking this but I'm going to ask anyway. I'm doing an assignment for my Intro to Comp Programming class. This is the assignment: Define a class named PhotoOps. Like you did in your last programming assignment, define the class with a String instance variable named _filename, and Picture instance variable named _picture. Define the constructor so that it accepts a String as an argument;...
0
8711
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8642
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8368
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
7203
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5576
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4206
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2630
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1815
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1515
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.