Click here to Skip to main content
15,890,512 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
TABLE NAME: USER

Id int
Email varchar(500)
Password varchar(500)
Name varchar(500)
DATA IN TABLE USER IS
Id  Email          Password     Name 
1  ali@yahoo.com    1234       ali                      is this row at position 0?
2  usman@yahoo.com  1234      usman                     is this row at position 1 ?


if (!Page.IsPostBack)
 {
            GetUserDetails(int.Parse(Request.QueryString["Id"].ToString()));
 }
 
public void GetUserDetails(int mu)
{
   string getUserDetail ="Select Id,Email,Name,Country FROM [User] where Id="+ mu+";
   dt = dbClass.ConnectDataBaseReturnDT(getUserDetail);
 
   if(dt.Rows.Count>0)//what this line do?
   {
      Label1.text=datatable.Rows[0]["Name"].Tostring();
      // i use for reterive the data from table User  1 ali@yahoo.com 1234 ali
 
      Label1.Text=datable.Rows[1]["Name"].Tostring();
      //i use for retrive the data from table User 2 usman@yahoo.com 1234 usman  
     // ERRRO COMES THERE IS NO ROW AT POSITION 1 
   }
}


[edit]Code blocks added - OriginalGriff[/edit]
Posted
Updated 9-May-11 8:30am
v2
Comments
Sandeep Mewara 10-May-11 2:24am    
Repost again!

changing ID does not change the question. :doh:

I think your problem is that you're assuming two records have been returned, when that might not actually be the case.

BTW, your example code is setting different text to the same label control twice.

Finally, you should always put try/catch blocks around code like that (and learn how to use the debugger - it'll save you DAYS of time).
 
Share this answer
 
v2
Comments
JOAT-MON 9-May-11 14:46pm    
@JSOP 5

@umairshoaib: Your query specifies the Id in the WHERE clause, so you should only be receiving one record for the user you specified. If you want more users to return from your query, you need to remove or modify the WHERE clause.
#realJSOP 9-May-11 14:58pm    
He's not gonna see your comment. Post it as an answer.
In addition to John's answer, it looks like you are trying to list the users in the table, but you have the WHERE clause set to filter the results to just one user. Your query specifies the Id in the WHERE clause, so you should only be receiving one record for the user you specified. If you want more users to return from your query, you need to remove or modify the WHERE clause.
 
Share this answer
 
Comments
#realJSOP 9-May-11 15:14pm    
5
Kim Togo 9-May-11 15:20pm    
Good catch, 5.

The method is names "GetUserDetails(int mu)", when I read the method name. It tells me: Get details about this one user. Not all users.

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