IndexOutOfRangeException未被for循环中的用户代码

时间:2016-10-21 06:47:02

标签: sql winforms c#-4.0

我在这里研究了其他答案,但没有一个真的适合我的情况。我已经在数据库中添加了一个表,现在我收到了这个错误。事情是,它在其他人的计算机上工作,但在我的,我得到以下错误。附:我的关系很好(如果你徘徊):

IndexOutOfRangeException未被用户代码

处理
An exception of type `System.IndexOutOfRangeException` occurred in System.Data.dll but was not handled in user code

其他信息:找不到表格0。

违规代码是for循环

中int i = 0的初始化

这是我的代码

 tableLayoutPanel1.RowCount = ds.Tables[0].Rows.Count;
            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
        {
            Label lbl = new Label();
            lbl.Text = ds.Tables[0].Rows[i]["RoleName"].ToString();
            tableLayoutPanel1.Controls.Add(lbl);
        }

0 个答案:

没有答案
相关问题