Click here to Skip to main content
15,898,581 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more: (untagged)
C#
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
Updated 24-Dec-11 8:18am
v2
Comments
Richard MacCutchan 24-Dec-11 14:31pm    
Are you sure that dtr contains 4 elements?

Because dtr doesn't have enough columns to support your code.
 
Share this answer
 
Comments
Monjurul Habib 24-Dec-11 14:39pm    
excellent,5!
C#
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();*/
    }
 
Share this answer
 
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.
 
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