title: "Index 0 is either negative or above row count" error C#
body: <p>I need help too much. </p>
  
  <p>I am getting the following exception:</p>
  
  <blockquote>
    <p>Index 0 is either negative or above row count error</p>
  </blockquote>
  
  <p>I researched in stackoverflow and google, but I couldn't fixed error.</p>
  
  <p>My code:</p>
  
  <pre><code>if (lb_Gmy.SelectedItems.Count &gt; 0)
  {
      string gmyquery = "Select * from tblA (nolock) where ParameterID = 2 and Status = 1";
      DataView dataw = new DataView(ReturnTable(gmyquery));
  
      foreach (string item in lb_Gmy.SelectedItems)
      {
          dataw.RowFilter = "Value = '" + item + "'";
          gmy += dataw[0]["ParamValue"].ToString() + ",";
      }
  
      gmy = gmy.Substring(0, gmy.Length - 1);
  }
  </code></pre>
  
  <p>But I am not getting an error in this code:</p>
  
  <pre><code>if (lb_Fg.SelectedItems.Count &gt; 0)
  {
      string gmyquery = "Select * from tblA (nolock) where ParameterID = 2 and Status = 1";
      DataView dataw = new DataView(ReturnTable(gmyquery));
  
      foreach (string item in lb_Fg.SelectedItems)
      {
          dataw.RowFilter = "Value = '" + item + "'";
          findingGmy += dataw[0]["ParamValue"].ToString() + ",";
      }
  
      findingGmy = findingGmy.Substring(0, findingGmy.Length - 1);
  }
  </code></pre>
  
  <p>They are looking same. I'm confused so much. Where is the problem? Tell me please.</p>