Click here to Skip to main content
16,016,759 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hi,

I am using 3 Tier architecture.
I have an ASP.net web form with Search button and Gridview.
If I enter studnetId in Textbox and If I click search button,the search result record should be displayed in a gridview below.

Here, I written the code for the search button and the search is working fine and displaying records in Gridview also.
Here my problem is I want the code to be implemented in 3-Layered architecure.
Can anyone tell me the 3 Tier for this example.

C#
protected void btnSearch_Click(object sender, EventArgs e)
       {
           BindGridView(txtStudentId.Text.Trim());
       }
       private void BindGridView(string field)
       {
           DataTable dt = new DataTable();
           //string constring = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
           SqlConnection conn = new SqlConnection("Data Source=.;Initial Catalog=STUDENT;User Id=sa;password=123;Integrated Security=True");
           string @DocketId = txtDocketIdSearch.Text;
           conn.Open();
           SqlCommand comm = new SqlCommand("SELECT studid,studname,studage FROM Student WHERE studid=@studid" , conn);
           comm.Parameters.AddWithValue("@studId", @StudId);
           SqlDataAdapter da = new SqlDataAdapter(comm);
           da.Fill(dt);
           SqlParameter param = new SqlParameter();

           if (dt.Rows.Count > 0)
           {
               GridView1.DataSource = dt;
               GridView1.DataBind();
           }
           else
           {
               Response.Write("No Records....");
           }


Please Let me know if my question is not clear...


Thank you,
Posted
Comments
Sergey Alexandrovich Kryukov 19-Jun-12 10:38am    
What do you mean "tell the 3 tier"? What would be "telling a tier"? How tiers are "told"? Based on what information? This fragment of code does not tell much. I don't see how this "question" can make any sense.
--SA

1 solution

Make a function in your Business layer which returns the filled datatable then databind the response of this function to your grid, that would be proper N-tier programming.
 
Share this answer
 

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