Seems like there ought to be a method that copies an object. If I do
something like this:
System.Data.Odbc.OdbcCommand cmd;
cmd = new OdbcCommand();
cmd.Connection = odbc_Categories;
cmd.CommandText = "SELECT * FROM \"tblCategory\" ORDER BY \"Category\"";
odbcDA_CatSubCats.SelectCommand = 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_CatSubCats.UpdateCommand = 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_CatSubCats.UpdateCommand = (OdbcCommand)cmd.MemberwiseClone();
I get this:
Cannot access protected member 'object.MemberwiseClone()' 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. 6 1724
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.
Bruce Wood <br*******@canada.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.Odbc;
class Test
{
static void Main()
{
OdbcConnection conn = new OdbcConnection();
OdbcConnection conn2 = (OdbcConnection)
((ICloneable)conn).Clone();
}
}
--
Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Excellent. I applied this to the OdbcCommand class and it worked fine.
Thanks.
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om... Bruce Wood <br*******@canada.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.Odbc;
class Test { static void Main() { OdbcConnection conn = new OdbcConnection();
OdbcConnection conn2 = (OdbcConnection) ((ICloneable)conn).Clone(); } }
-- Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet If replying to the group, please do not mail me too
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om... Bruce Wood <br*******@canada.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.Odbc;
class Test { static void Main() { OdbcConnection conn = new OdbcConnection();
OdbcConnection conn2 = (OdbcConnection) ((ICloneable)conn).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
Mythran <ki********@hotmail.comREMOVETRAIL> 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.com> http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om... Mythran <ki********@hotmail.comREMOVETRAIL> 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.com> 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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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...
|
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,...
|
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...
|
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...
|
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++...
| |
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
...
|
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...
|
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...
|
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...
|
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...
|
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,...
| |
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...
|
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...
|
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...
|
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,...
|
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...
|
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...
| |
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...
| |