I am writing an application using 3-tier layer.
In presentation layer, I have a combobox that I need to populate with a simple SQL such as
SELECT distinct(Item) as items From ItemsTable order by items;
AFAIK, presentation layer shouldn't know about the name of the item column. Maybe the name will be changed in DB and I don't want to update the entire application, in the worst case only the DAL.
My question is how can I populate the combobox without having to write the name of the column (items)
ItemsComboBox.DisplayMember = "items";
ItemsComboBox.DataSource = _businessLayer.GetListOfItems();
Business Layer:
public DataTable GetListOfItems()
{
return DataAccess.Instance.Retrieve("TableName", "items");
}
You should define a class specifically for the transfer of data between the business layer and presentation layer. This is called a data transfer object. It will not hurt to reuse the same naming for the properties in DTO classes as the column names from your entities. Your business layer method would get the data from the database, populate the DTO and return it to the calling method in the presentation layer. The same object can be used to pass data back. If a column name then changes in the entity, you can amend the database access in the business layer without affecting the presentation layer. There are some great videos on application architecture by Bob Tabor on youtube. He explains it all very well.