Hi Cor
The class was needed to provide an easy to use standard, for seperating the
GUI and the Database, so the GUI layer was totally removed from the business
layer and the database layer.
Its a bit more involved but in essence, the class needed to hold a value, a
fieldname, a flag to say an update was required and a method to prepare
itsself in a common way for one of a standardised stored procedure. One
stored procedure handles DateTime updates, another VARCHAR updates, another
Decimal (for currency) etc...
The objects created needed to be of a common base, so I could easily add to
an array list, meaning I could use foreach.. if myclass.changereq = true
then ...UpdateDatabase()
My initial thought (and post) was to overload the accessors, so If the
stored value was a DateTime, UpdateDataBase() would return Value and get its
base class variable and the over loading would know to return a DATETIME
value, Varchar with a string etc...
After reading the replies, it seemd it couldn't be done other than by
converts and object classes.
However, It turned out to be easy when I thought about it ( I should have
been more carefull at the start!), all I needed was a class that I could
inherit from my base class that had UpdateDataBase(), change pending etc
defined. The inherited classes overrode UpdateDataBase() method, and used
their own variable types.
so I have base class --UpdateDataBase()
then I inherit from it for say a
DateManager class, that has its own Dataype Value of DateTime plus an
overridden UpdateDataBase()
a StringManager class, that has its own DataypeValue of String plus an
overridden UpdateDataBase()
it was easy to add each object to an ArrayList and when I need to update I
can use foreach, check the Update required, flag, and then call the
UpdateDatabase flag
worked a treat
I'm new to C# and OOPS so things that used to come easily, I now have to
think about much more, so thanks again everyone who responded
Andy
"Cor Ligthert [MVP]" <no************@planet.nlwrote in message
news:Og**************@TK2MSFTNGP02.phx.gbl...
AAJ,
Nice you found it, but I am curious about the sence, can you explain that
to us?
Cor
"AAJ" <a.a.comschreef in bericht
news:OA**************@TK2MSFTNGP04.phx.gbl...
>Thanks all for the rapid answers!!!
the genreal consensus is its not the way to go...
I just started typing a long winded reply with full details of my
problem, but as so often happens when you stop and think, an alternative
solution popped into my head.
It turns out I can use an inherited Abstract base class to form a
structure, and overide the bits I need for managing the type conversions
thanks again for all the replies
Andy
"AAJ" <a.a.comwrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
>>Hi all
I would like to have a class that can set/return values of different
datatype via a single accessor, i.e. overload the accessor
i.e. something like
DateTime m_DateValue;
string m_StringValue;
public string Value
{
get { return m_StringValue; }
set { m_StringValue = value; }
}
public DateTime Value
{
get { return m_DateValue; }
set { m_DateValue = value; }
}
so I can use something like
ValueHandler testDate = new ValueHandler();
testDate.Value = "1/1/2006";
DateTime returndate = testDate.Value;
As well as
ValueHandler testString = new ValueHandler();
testString.Value = "My test String";
string returnString = testString.Value;
i.e. depending on the datatype, I can use the same accessor to store in
either a DateTime field or a string field
is there anyone who knows how to do this
thanks
Andy