title: Get number of rows if equal to zero - DB2
body: <p>I am trying to see if a record exists in the database by counting the rows. I have code which counts the number of rows and returns the number of rows (1,2,3 etc) so that record exists in the database. Is there away to count the rows but only return a message if the number of rows equal 0 (so the record doesn't exist in the database)?</p>
  
  <pre><code>while (dbReader.Read())
                  {
                      int fCount = dbReader.FieldCount;
  for (int i2 = 0; i2 &lt; fCount; i2++)
  {
       string col = dbReader.GetString(i2);
  
        string strExist = "Record Exists";
       ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('" + strExist + "');", true); 
  }
  }
  Some Code --- 
  {
      // Record doesn't exist in database.
  }
  </code></pre>
  
  <p>I'm using C# with DB2 database.</p>
  
  <p>When I do an If statement</p>
  
  <pre><code>if fcount == 0, 
  </code></pre>
  
  <p>after I debug it, it states Exception Details: System.InvalidOperationException: No data exists for the row/column. On line string col = dbReader.GetString(i2);</p>
  
  <p>I know the data doesn't exist but instead I want a message not this error. </p>