In my class I have private variables and properties like this.
private string _itemCOde=string.Empty;
private string _itemName=string.Empty;
public string
You can dynamically associate names and values with each other using a Dictionary<TKey,TValue>. You could combine this with your own wrapper using the indexer:
public string this[this key]
{
get { return dictionary[key]; }
set { dictionary[key] = value == null ? null : value.Trim(); }
}
Still, if the database changes, then you really should probably change your object because it changed.
Maybe what you need is a Dictionary.
Take a look at DynamicObject. You can wrap a System.Data.DataRow in one to get the functionality that I think you are after.
http://msdn.microsoft.com/en-us/library/system.dynamic.dynamicobject.aspx
You could use an ExpandoObject:
Represents an object whose members can be dynamically added and removed at run time.
dynamic expando = new ExpandoObject();
expando.Cost= 42.0;
expando.ItemName = "Shoes";
If new columns are added to the databases you need to alter your code to specify how new columns should be used.
If you need just to show content of the table despite of the field in the table, then you could use DataTable
class.
If you need to keep the class attributes in sync with the SQL table schema... What you need is LINQ to SQL