Click here to Skip to main content
15,896,557 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
i have 3 tables one is Tbl_Project(projectcode PK ,projectname,remarks) ; Tbl_users(usercode PK,username); Tbl_Clientprojects(projectcode FK,usercode FK) and have one web form in which i have dropdownlist (in which projectname from Tbl_project arethere); i have gridview1 (in which all username with their respective code are there and with one more column checkbox to select to which users to make select respective project which will be selected from dropdownlist) and one <b>OK </b>button(whose work is to insert the project code to respective usercode (which is checked in checkbox)) and respective user when they login respective account should get only their information about the project assigned to them ) i have achieved all this but problem arised when one user get multiple projects.it is showing only one project.following code:
C#
foreach (GridViewRow r in GridView1.Rows)
        {
            ch = (CheckBox)(r.FindControl("checkSelect"));
            if (ch.Checked)
            {

                userCode = r.Cells[1].Text;
              objquery.assign_pro(projectCode, userCode, userType, status,s,s1,s,s1);

            }
        }

 public void assign_pro(string projectCode, string userCode, string userType, string status, string CreatedBy, string created_date, string ModifiedBy, string modified_date)
         {
             objdl.DMLQuery("insert into Tbl_ClientProject values('" + projectCode + "','" + userCode + "','" + userType + "','" + status + "','" + CreatedBy + "','" + created_date + "','" + ModifiedBy + "','" + modified_date + "'  )");
         }
public void DMLQuery(string commText)
      {
          comm = new SqlCommand(commText, conn);
          comm.Transaction = trans;
          comm.ExecuteNonQuery();
      }


til here it is working correct i.e one user is assigned with multiple projects
now when user open its project after login as user to whom only its project should be shown
C#
protected void Page_Load(object sender, EventArgs e)
   {
       lblWelcome.Text = "Welcome " + Session["UserId"];
      string s=Session["UserId"].ToString();
      dt= objquery.get_clientprojectcode(s);

      string s1 = dt.Rows[0]["ProjectCode"].ToString();
      dt = objquery.get_clientprojects(s1);

        foreach (DataRow dr in dt.Rows) 

                {
                         
                         string s1 = dr["ProjectCode"].ToString();
                         dt1 = objquery.get_clientprojects(s1);
                       
                        
                      // here i am having 2 records in datatable but it is showing  only one record in grid
                        
                         
                 }
            GridViewuser.DataSource = dt1;
            GridViewuser.DataBind();   }

 public DataTable get_clientprojects(string pid)
         {
             return (objdl.getData("select ProjectName,Remarks from Tbl_Project where ProjectCode='" + pid + "'"));
         }
 public DataTable getData(string commText)
        {
            adapt = new SqlDataAdapter(commText, conn);
            dt = new DataTable();
            adapt.Fill(dt);
            return dt;
        }

in dt it is showing only one record assigned to it but in table there are two records
here i have assigned 2 projects to this user ...this user only getting one project shown in grid not 2
pls tell how can i achieve
regards
Posted
Updated 12-Mar-13 1:35am
v3
Comments
José Amílcar Casimiro 12-Mar-13 6:42am    
If I interpreted correctly, you select the table "Tbl_Clientprojects" through the column "projectcode" when shouldst be to select the records for "usercode".

The code would be simpler through LINQ.
shivani 2013 12-Mar-13 7:34am    
i need to achieve through this only and one more thing .instance is i have two records for user A but when i need to show it on grid it is only displaying one record only thogh datatble having 2 records.pls tell how to achieve it

1 solution

Because you are doing an assignment (dt1 = objquery.get_clientprojects(s1);) every time you go through a data row.
That means that you will always and only see the last item in your dt.Rows collection. You need to write a method that will take all the rows returned by the objquery.get_clientprojects(s1) method and add them using the dt1.Rows.Add() method.
 
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