I have a base class (written using C#.net) which uses datasets to pull data from DB and the connection string is in App.config file. So after writing the base class it has been compiled into dll.
And to use this base class for different project I have to override the DB connection string, so first is it possible to do and if possible, can anyone give me an example for it?
I would suggest giving your class an overloaded constructor, like this:
Then the derived class can just pass the “overridden” connection string into the constructor.
I think this is cleaner than using polymorphism with a virtual property etc – especially as presumably the connection string isn’t going to change over the course of the object’s lifetime. You’re not really changing the behaviour (which is what polymorphism’s good for) – you’re changing the initialization (which is what constructor parameters are good for).