8 Oct 2009 05:49
Multiple method or different class for a ComboBox loading?
Foysal <foyzulkarim <at> yahoo.com>
2009-10-08 03:49:17 GMT
2009-10-08 03:49:17 GMT
Hello everyone. I am new in this group. I use layer architecture in my
work. I am in a situation described below:
DAO: Company (Company object: has Id and Name)DAL: CompanyGateway
(Queries are handled in here)BLL: CompanyManager (Business logics are
checked in here)UI: CompanyUI (User Interface)
I have a combo in UI which loads company names into it. Generally, we
write a GetAllCompanies() method in CompanyGateway class. But sometimes
we need to fetch different data for different combo in a project. So, we
need to write different methods for each DAO objects in separate Gateway
classes.
But if i want to create a method ( LoadCombo() )in a separate class (
suppose: ComboLoader.cs) where i will give the table name or other
specific parameters and the method's only responsibility is to return a
data table for loading the combo, how it sounds?
I am giving the code snippet for your better understanding. I am using
C# as the language.
========================================================================\
=========
public DataTable ComboLoader(string tableName) {
string selectQuery = "SELECT * FROM [" + tableName + "]";
SqlDataAdapter adapter=new
SqlDataAdapter(selectQuery,DBConnector.SqlConnectionObj);
DataTable dataTable=new DataTable(); try {
DBConnector.OpenSqlConneciton(); adapter.Fill(dataTable);
} catch (Exception exception) {
throw new Exception("Data could not retrived from database.",exception);
} finally {
DBConnector.CloseSqlConnection(); } return
dataTable; }
========================================================================\
(Continue reading)
RSS Feed