문제

I have a DatagridView and i want to populate it with the contents of a database. I know it can be done through DataAdapter, dataset and Fill/Update commands and all. But what I want to know is, how to write it in a 3tier architecture. I mean, what will be the commands in the Presentation layer, Business layer and Data layer. I am new born baby for 3tier architecturre. And not able to get it right.Thanks.

도움이 되었습니까?

해결책

After googling it for a while and implementing some of my techniques, I came upto this:

UILayer:

private void FillData(object sender, EventArgs e)
{
   BusinessObject bo = new BusinessObject();
   Datatable dt = new Datatable();
   dt = bo.getTable();
   datagridview.DataSource = dt;
}

BusinessLayer:

public DataTable getTable()
{
   DataLayer dl = new DataLayer();
   DataTable dt = new DataTable();
   dt = dl.getTable();

   if(dt == null || dt.HasErrors == true)
   {
      MessageBox.Show("Datable has Errors or is Null");
      return
   }
   return dt;
}

DataLayer:

public DataTable getTable()
{
   SqlConnection con = new SqlConnection(connectionString);
   string myCommand = "Select empId, empDesignation from Employees";
   con.Open();
   SqlDataAdapter sda = new SqlDataAdapter(myCommand, con);
   DataTable dt = new DataTable();
   sda.Fill(dt);
   return dt;
}

Hope it helps.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top