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 )
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.
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.
BAL.Patient opatient=new BAL.Patient();
gvPatients.DataSource=opatient.GetAllPatients();
gvPatients.DataBind();
skillgun