Click here to Skip to main content
15,904,339 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how to populate in gridview using 3 tier architecture
Posted

It is simple , please refer the below explanation.

1.Create a DAL Project using ( class library )
2.Create a Database and create a table for storing patient details ( pid int, pname varchar(30), email varchar(30))
3.Insert data into the patients table.
4.In DAL Create a class file with the name Patient.cs ( see code given for Patient.cs )

C#
public class Patient
  {
    public DataSet GetAllPatients()
    {
        SqlConnection cn = new SqlConnection("your connection string/prefered to get from       app.config file");
        SqlCommand cmd = new SqlCommand("select * from patients", cn);
        SqlDataAdapter da = new SqlDataAdapter();
        da.SelectCommand = cmd;
        DataSet ds = new DataSet();
        da.Fill(ds);
        return ds;
    }
  }

5.Create another class library project with the name BAL in the same solution where DAL project
is present.
6.Create a class file with name Patient.cs
7.Add DAL class library reference to BAL project .
8.IN BAL create a class file with the name Patient.cs as shown below.

C#
using DAL;
using System.Data;
using System.Data.SqlClient;

public class Patient
{
    public DataSet GetAllPatients()
    {
        DAL.Patient oPatient=new DAL.Patient();
        return oPatient.GetAllPatients();
    }
}


9.Now create asp.net or winforms application with name as UI and add patients.aspx page if it is asp.net application.
10.Add BAL class library reference to the UI Project.
11.Add a grid view control to the patients.aspx page with the name gvPatients
12.In Patients.aspx.cs page write the below code in Page_Load method as shown below.
C#
BAL.Patient opatient=new BAL.Patient();
gvPatients.DataSource=opatient.GetAllPatients();
gvPatients.DataBind();

skillgun
 
Share this answer
 
Comments
Member 10823759 29-May-14 19:35pm    
thank you this helped me out!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900