title: retrieving number value from datagridview C#
body: <p>I am trying to retrieve a numerical value from datagridview. The data type for both the value in the table, and the variable (weeklyTotal), are integer. Also I am trying to cast it into integer. I looked through the whole website for similar problems, and yet none of the solutions were helpful. The error message that I am getting is “when casting form a number, the value must be less than infinity”. I went back to my table more than one time to make sure that I don’t have invalid value.</p>
  
  <p>it's a runtime error and the IDE always point at this line</p>
  
  <p><strong>weeklyTotal += (int)dataGridView1.Rows[i].Cells[1].Value;</strong></p>
  
  <pre><code>for (int i = 0; i &lt; this.dataGridView1.Rows.Count; i++)
          {
              sdate = dataGridView1.Rows[i].Cells[2].Value.ToString();
              ddate = dataGridView1.Rows[i].Cells[3].Value.ToString();
  
              if ((weekFirstDay &lt;= Convert.ToInt32(sdate) &amp;&amp;
                  Convert.ToInt32(sdate) &lt;= (weekFirstDay + 7))||(weekFirstDay &lt;= `Convert.ToInt32(ddate) &amp;&amp;`
                  Convert.ToInt32(ddate) &lt;= (weekFirstDay + 7)))
              {
                  dataGridView1.Rows[i].Selected = true;
                  dataGridView1.Rows[i].Visible = true;
                  weeklyTotal += (int)dataGridView1.Rows[i].Cells[1].Value;
  
                  //weeklyTotalString = dataGridView1.Rows[i].Cells[1].Value.ToString();
                  //weeklyTotal += Convert.ToInt32(weeklyTotalString);
  
  
              }
              else
  </code></pre>