C
Christopher Weaver
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.
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.