简体   繁体   English

错误位置1没有行

[英]Error There is no row at position 1

I am getting an exception 我有一个例外

System.ArgumentOutOfRangeException: There is no row at position 1. RBTree`1.GetNodeByIndex(Int32 userIndex)** System.ArgumentOutOfRangeException:在位置1没有行。RBTree`1.GetNodeByIndex(Int32 userIndex)**

There is no row at position can be 0 or 1 or 2 . 位置没有行可以是0或1或2。 I guess i am trying to read or write some array elements which are outside of your array boundary. 我想我正在尝试读取或写入数组边界之外的一些数组元素。 The code snippet is shown below 该代码段如下所示

public void ManageAlarm(string textName, int leaveValue)
{
   try
   {
      int indices = team.Find(textName);
      if (indices >= 0)
      {
         DataRow row = teamTable.Rows[indices];
         row[m_leaveValues] = leaveValue;
      }
   }

What should i do here to prevent this alert trace 我在这里应该怎么做以防止此警报跟踪

You need to check the rows count in m_tblAlert before you access rows in it. 您需要先检查m_tblAlert中的行数,然后才能访问其中的行。 m_tblAlert.Rows.Count must be greater then indx

public void ManageDuplicateAlarm(string alertName, int dupValue)
{
   try
   {
      int indx = m_alerts.Find(alertName);
      if (indx >= 0 && m_tblAlert.Rows.Count > indx)
      {
         DataRow row = m_tblAlert.Rows[idx];
         m_dcDuplicates.ReadOnly = false;
         row[m_dcDuplicates] = dupValue;
         m_dcDuplicates.ReadOnly = true;
      }
   }

Edit more exlanation on OP comment 编辑关于OP评论的更多说明

You are checking indx >= 0 to make sure that that -1 could not be row index for statement m_tblAlert.Rows[idx]; 您正在checking indx >= 0 to make sure that that -1 could not be row index语句m_tblAlert.Rows [idx]的checking indx >= 0 to make sure that that -1 could not be row index Similarly you need to check if the value return by m_alerts.Find(alertName) must be valid row number ie it should not be greater then the number of rows you have in data table. Similarly you need to check if the value return by m_alerts.Find(alertName) must be valid row number ie it should not be greater then the number of rows数据表中Similarly you need to check if the value return by m_alerts.Find(alertName) must be valid row number ie it should not be greater then the number of rows

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM