Click here to Skip to main content
12,406,124 members (43,474 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: (untagged)
cmd = new SqlCommand("select RefferBy from UsersIncome where UserName='" + Label1.Text + "'", con);
 
    dtr = cmd.ExecuteReader();
        if (dtr.Read())
    {
       Label2.Text = dtr[0].ToString();
       Label3.Text = dtr[1].ToString();
        Label4.Text = dtr[2].ToString();
       Label5.Text = dtr[3].ToString();
    }


it is showing Index was outside the bounds of the array why ?????
Posted 24-Dec-11 8:05am
Pr!y@1.2K
Updated 24-Dec-11 8:18am
v2
Comments
Richard MacCutchan 24-Dec-11 14:31pm
   
Are you sure that dtr contains 4 elements?
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

Because dtr doesn't have enough columns to support your code.
  Permalink  
Comments
Monjurul Habib 24-Dec-11 14:39pm
   
excellent,5!
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

cmd = new SqlCommand("select RefferBy from UsersIncome where UserName='" + Label1.Text + "'", con);
 
    dtr = cmd.ExecuteReader();
        if (dtr.Read())
    {
       Label2.Text = dtr[0].ToString();
       /*Label3.Text = dtr[1].ToString();
        Label4.Text = dtr[2].ToString();
       Label5.Text = dtr[3].ToString();*/
    }
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 3

Check out SQL Tutorial[^] for basic understanding of SQL syntax.

The problem with your code is, that there is only 1 column in your SELECT statement. "RefferBy".

If you want to read all rows, you have to loop the DataReader.
Check out Retrieving Data Using a DataReader[^]

Hope it can help you.
  Permalink  

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160726.1 | Last Updated 24 Dec 2011
Copyright © CodeProject, 1999-2016
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