C# parse string "0" to integer
<p>I have a new laptop at work and code that worked earlier in the week does not work today.</p>

<p>The code that worked before is, simplified: </p>

<pre><code>while (dr.Read())
{
    int i = int.Parse(dr.GetString(1))
}
</code></pre>

<p>Now it fails when the database value is 0. Sometimes, but not reliably, this will work instead:</p>

<pre><code>while (dr.Read())
{
    int i = Convert.ToInt32(dr["FieldName"]))
}
</code></pre>

<p>Am I missing something stupid?</p>

<p>Oddly enough, ReSharper is also having tons of weird errors with the same error message that I am getting with the above code: "input string was not in the correct format." (Starts before I even load a project.)</p>

<p>Any ideas? Anyone having any SP issues? I did try to make sure all my SPs were up-to-date when I got the machine.</p>

<p>EDIT: I understand how to use Try.Parse and error-handling. The code here is simplified. I am reading test cases from a database table. This column has only 0, 1, and 2 values. I have confirmed that. I broke this down putting the database field into a string variable s and then trying int.Parse(s). The code worked earlier this week and the database has not changed. The only thing that has changed is my environment.</p>

<p>To completely simplify the problem, this line of code throws an exception ("input string was not in the correct format"):</p>

<pre><code> int.Parse("0");
</code></pre>

<p>EDIT: Thanks to everyone for helping me resolve this issue! The solution was forcing a reset of my language settings.</p>
