Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. In 3 tier architecture , filling textboxes with values from database table

In 3 tier architecture , filling textboxes with values from database table

Scheduled Pinned Locked Moved ASP.NET
databasecsswpfwcfarchitecture
11 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Member_14185275
    wrote on last edited by
    #1

    Hi Friends, Can anyone help me with this? Using 3 tier architecture,how to fetch data directly from database table to textboxes when I clicked on select button in grid view,I have a table in SQL database.Upon clicking on select link button in grid view,the selected row values must be fetched from database table to text boxes and must be filled with respective values according to database table.I have used sqldatareader, taken OnSelectedIndexChanged ,written query in stored procedure for fetching selected row but values are not binding to text boxes.Any suggestions would be helpful.

    L 1 Reply Last reply
    0
    • M Member_14185275

      Hi Friends, Can anyone help me with this? Using 3 tier architecture,how to fetch data directly from database table to textboxes when I clicked on select button in grid view,I have a table in SQL database.Upon clicking on select link button in grid view,the selected row values must be fetched from database table to text boxes and must be filled with respective values according to database table.I have used sqldatareader, taken OnSelectedIndexChanged ,written query in stored procedure for fetching selected row but values are not binding to text boxes.Any suggestions would be helpful.

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      As you did not showed what you have tried it will be hard us to know. Did you tried to debug and see if you really pulling any values back on your event to bind?

      M 1 Reply Last reply
      0
      • L Lost User

        As you did not showed what you have tried it will be hard us to know. Did you tried to debug and see if you really pulling any values back on your event to bind?

        M Offline
        M Offline
        Member_14185275
        wrote on last edited by
        #3

        DAL: public DataTable FetchDetails(string pid, string pname, string pcid, string sdesc, string desc, string qty, string prce, string len) { var a = new ArrayList(); SqlCommand cmd = new SqlCommand("spfetchdetail", con); con.Open(); cmd.ExecuteNonQuery(); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@pid", pid); SqlDataAdapter sda = new SqlDataAdapter(cmd); DataTable dt = new DataTable(); sda.Fill(dt); SqlDataReader sdr = cmd.ExecuteReader(); while (sdr.Read()) { pid = sdr["P_id"].ToString(); pname = sdr["P_name"].ToString(); pcid = sdr["c_name"].ToString(); sdesc = sdr["P_shortdesc"].ToString(); desc = sdr["P_desc"].ToString(); qty = sdr["P_qty"].ToString(); prce = sdr["P_price"].ToString(); len = sdr["P_length"].ToString(); a.Add(pid); a.Add(pname); a.Add(pcid); a.Add(sdesc); a.Add(desc); a.Add(qty); a.Add(prce); a.Add(len); } return dt; } BAL: public object fetchdetail(string pid, string pname, string pcid, string sdesc, string desc, string qty, string prce, string len) { return dll.FetchDetails(pid, pname, pcid, sdesc, desc, qty, prce, len); } CS: protected void GridView1_SelectedIndexChanged(object sender, EventArgs e) { string pid = ""; string pname = ""; string pcid = ""; string sdesc = ""; string desc = ""; string qty = ""; string prce = ""; string len = ""; bll.fetchdetail(pid, pname, pcid, sdesc, desc, qty, prce, len); HiddenField1.Value = pid; txt_proName.Text = pname; ddl_category.SelectedValue = pcid; txt_sdesc.Text = sdesc; txt_ldesc.Text = desc; txt_qnty.Text = qty; txt_price.Text = prce; txt_len.Text = len; }

        L 1 Reply Last reply
        0
        • M Member_14185275

          DAL: public DataTable FetchDetails(string pid, string pname, string pcid, string sdesc, string desc, string qty, string prce, string len) { var a = new ArrayList(); SqlCommand cmd = new SqlCommand("spfetchdetail", con); con.Open(); cmd.ExecuteNonQuery(); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@pid", pid); SqlDataAdapter sda = new SqlDataAdapter(cmd); DataTable dt = new DataTable(); sda.Fill(dt); SqlDataReader sdr = cmd.ExecuteReader(); while (sdr.Read()) { pid = sdr["P_id"].ToString(); pname = sdr["P_name"].ToString(); pcid = sdr["c_name"].ToString(); sdesc = sdr["P_shortdesc"].ToString(); desc = sdr["P_desc"].ToString(); qty = sdr["P_qty"].ToString(); prce = sdr["P_price"].ToString(); len = sdr["P_length"].ToString(); a.Add(pid); a.Add(pname); a.Add(pcid); a.Add(sdesc); a.Add(desc); a.Add(qty); a.Add(prce); a.Add(len); } return dt; } BAL: public object fetchdetail(string pid, string pname, string pcid, string sdesc, string desc, string qty, string prce, string len) { return dll.FetchDetails(pid, pname, pcid, sdesc, desc, qty, prce, len); } CS: protected void GridView1_SelectedIndexChanged(object sender, EventArgs e) { string pid = ""; string pname = ""; string pcid = ""; string sdesc = ""; string desc = ""; string qty = ""; string prce = ""; string len = ""; bll.fetchdetail(pid, pname, pcid, sdesc, desc, qty, prce, len); HiddenField1.Value = pid; txt_proName.Text = pname; ddl_category.SelectedValue = pcid; txt_sdesc.Text = sdesc; txt_ldesc.Text = desc; txt_qnty.Text = qty; txt_price.Text = prce; txt_len.Text = len; }

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          Couple of issues with your code in

          FetchDetails

          method. 1. You have populated the result into arraylist object which is local to this function 2. You executing command object with ExecuteNonQuery, Reader and DataAdapter 3. You populated Dataset to return from FetchDetails in DAL and did not received it in calling method to bind data. Populate your local variables in SelectChange event from DataSet object you reveiced from BAL and should work for you.

          M 1 Reply Last reply
          0
          • L Lost User

            Couple of issues with your code in

            FetchDetails

            method. 1. You have populated the result into arraylist object which is local to this function 2. You executing command object with ExecuteNonQuery, Reader and DataAdapter 3. You populated Dataset to return from FetchDetails in DAL and did not received it in calling method to bind data. Populate your local variables in SelectChange event from DataSet object you reveiced from BAL and should work for you.

            M Offline
            M Offline
            Member_14185275
            wrote on last edited by
            #5

            Thank u for u r response. Unfortunately I am new to work with three tier, I am unable to get your point.Could u pls modify the code which i have provided so that it will be very helpful for me.

            L 1 Reply Last reply
            0
            • M Member_14185275

              Thank u for u r response. Unfortunately I am new to work with three tier, I am unable to get your point.Could u pls modify the code which i have provided so that it will be very helpful for me.

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              Here you go. You need to extract data from data table now in below code to populate your variables which you may be binding on screen. DAL:

              public DataTable FetchDetails()
              {
              con.Open();
              DataTable dt = new DataTable();
              using(SqlCommand cmd = new SqlCommand("spfetchdetail", con))
              {
              cmd.CommandType = CommandType.StoredProcedure;
              cmd.Parameters.AddWithValue("@pid", pid);

                  SqlDataAdapter sda = new SqlDataAdapter(cmd);
                  sda.Fill(dt);
              }
              return dt.Table\[0\];
              

              }

              BAL:

              public DataTable fetchdetail()
              {
              return dll.FetchDetails(); // Call to your DAL returning Datatable
              }

              CS:

              protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
              {
              string pid = ""; string pname = ""; string pcid = ""; string sdesc = ""; string desc = ""; string qty = ""; string prce = ""; string len = "";
              DataTable dt = bll.fetchdetail(); // Call to BAL and reveice datatable
              // extract the data from this datatable now to populate your variables now
              HiddenField1.Value = pid;
              txt_proName.Text = pname;
              ddl_category.SelectedValue = pcid;
              txt_sdesc.Text = sdesc;
              txt_ldesc.Text = desc;
              txt_qnty.Text = qty;
              txt_price.Text = prce;
              txt_len.Text = len;
              }

              M 1 Reply Last reply
              0
              • L Lost User

                Here you go. You need to extract data from data table now in below code to populate your variables which you may be binding on screen. DAL:

                public DataTable FetchDetails()
                {
                con.Open();
                DataTable dt = new DataTable();
                using(SqlCommand cmd = new SqlCommand("spfetchdetail", con))
                {
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@pid", pid);

                    SqlDataAdapter sda = new SqlDataAdapter(cmd);
                    sda.Fill(dt);
                }
                return dt.Table\[0\];
                

                }

                BAL:

                public DataTable fetchdetail()
                {
                return dll.FetchDetails(); // Call to your DAL returning Datatable
                }

                CS:

                protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
                {
                string pid = ""; string pname = ""; string pcid = ""; string sdesc = ""; string desc = ""; string qty = ""; string prce = ""; string len = "";
                DataTable dt = bll.fetchdetail(); // Call to BAL and reveice datatable
                // extract the data from this datatable now to populate your variables now
                HiddenField1.Value = pid;
                txt_proName.Text = pname;
                ddl_category.SelectedValue = pcid;
                txt_sdesc.Text = sdesc;
                txt_ldesc.Text = desc;
                txt_qnty.Text = qty;
                txt_price.Text = prce;
                txt_len.Text = len;
                }

                M Offline
                M Offline
                Member_14185275
                wrote on last edited by
                #7

                Thank u soo much for your reply. But unfortunately i'm getting error in DAL The name 'pid' does not exist in the current context This is my Stored Procedure: CREATE proc [dbo].[spfetchdetail] @pid int as begin select * from Products LEFT JOIN Category ON Products.P_C_id=Category.c_id where P_id=@pid end

                L 1 Reply Last reply
                0
                • M Member_14185275

                  Thank u soo much for your reply. But unfortunately i'm getting error in DAL The name 'pid' does not exist in the current context This is my Stored Procedure: CREATE proc [dbo].[spfetchdetail] @pid int as begin select * from Products LEFT JOIN Category ON Products.P_C_id=Category.c_id where P_id=@pid end

                  L Offline
                  L Offline
                  Lost User
                  wrote on last edited by
                  #8

                  I might have removed all params so its error. You should pass the pid as parameter to DAL to resolve it.

                  M 1 Reply Last reply
                  0
                  • L Lost User

                    I might have removed all params so its error. You should pass the pid as parameter to DAL to resolve it.

                    M Offline
                    M Offline
                    Member_14185275
                    wrote on last edited by
                    #9

                    In DAL public DataTable FetchDetails(int pid) { con.Open(); DataTable dt = new DataTable(); using (SqlCommand cmd = new SqlCommand("spfetchdetail", con)) { cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@pid", pid); SqlDataAdapter sda = new SqlDataAdapter(cmd); sda.Fill(dt); } return dt; } In BAL: public DataTable fetchdetail(int pid) { return dll.FetchDetails(pid); } In CS page,passing pid string pid="";string pname = ""; string sdesc = ""; string desc = ""; string qty = ""; string prce = ""; string len = ""; DataTable dt = bll.fetchdetail(pid); getting type conversion error

                    L 1 Reply Last reply
                    0
                    • M Member_14185275

                      In DAL public DataTable FetchDetails(int pid) { con.Open(); DataTable dt = new DataTable(); using (SqlCommand cmd = new SqlCommand("spfetchdetail", con)) { cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@pid", pid); SqlDataAdapter sda = new SqlDataAdapter(cmd); sda.Fill(dt); } return dt; } In BAL: public DataTable fetchdetail(int pid) { return dll.FetchDetails(pid); } In CS page,passing pid string pid="";string pname = ""; string sdesc = ""; string desc = ""; string qty = ""; string prce = ""; string len = ""; DataTable dt = bll.fetchdetail(pid); getting type conversion error

                      L Offline
                      L Offline
                      Lost User
                      wrote on last edited by
                      #10

                      Well gave you direction but cant fix all here as it wont run. You need to debug and identify the issue. check if you really have data coming from SP outout in debug

                      M 1 Reply Last reply
                      0
                      • L Lost User

                        Well gave you direction but cant fix all here as it wont run. You need to debug and identify the issue. check if you really have data coming from SP outout in debug

                        M Offline
                        M Offline
                        Member_14185275
                        wrote on last edited by
                        #11

                        Thank u so much vinod, i have modified the code a little and its perfectly working now.Thank u for ur time.

                        1 Reply Last reply
                        0
                        Reply
                        • Reply as topic
                        Log in to reply
                        • Oldest to Newest
                        • Newest to Oldest
                        • Most Votes


                        • Login

                        • Don't have an account? Register

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • World
                        • Users
                        • Groups