Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#3.0 ASP.NET .NET4
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:
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
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 12-Mar-13 1:32am
Edited 12-Mar-13 2:35am
v3
Comments
   
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 at 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

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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.
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 490
1 Maciej Los 305
2 Richard MacCutchan 270
3 Mathew Soji 220
4 BillWoodruff 210
0 OriginalGriff 8,834
1 Sergey Alexandrovich Kryukov 7,477
2 DamithSL 5,689
3 Maciej Los 5,329
4 Manas Bhardwaj 4,986


Advertise | Privacy | Mobile
Web02 | 2.8.1411028.1 | Last Updated 12 Mar 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100