Click here to Skip to main content
15,894,460 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
i get error below code only
str2 += strListItems[i] + ":" + ds.Tables[0].Rows[comboBox1.SelectedIndex][i].ToString() + "\r\n";


the error is indexoutofrange Exception.
and my full code is
string str2 = "";
            string[] strListItems = { ds.Tables[0].Columns[1].ToString(), ds.Tables[0].Columns[0].ToString(), ds.Tables[0].Columns[2].ToString() };
            for (int i = 0; i < ds.Tables[0].Rows.Count -1; i++)
            {
                str2 += strListItems[i] + ":" + ds.Tables[0].Rows[comboBox1.SelectedIndex][i].ToString() + "\r\n";
            }
            textBox1.Text = str2;

Please give me any idea to resolve it

Thanks
VenkatS
Posted
Updated 14-Jun-11 0:52am
v2

So, if there are more than 3 rows in ds.Tables[0] where are they supposed to go?

You need to look at your definition of strListItems - you declare it with a fixed number of rows, but do not check if you are outside that.
 
Share this answer
 
The problem is If the ds.Tables[0].Rows.Count has more than 3 then it will raise error in strListItems which has 3 values. Because you put the strListItems in for loop, just think if the table contains more rows, that's why it raised the error.
 
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