Object cannot be cast from DBNull to other types
<p>I am trying to save the gridview data into the database. To decide if it should be an Insert or update, i need to find out if the <code>Order_SelectionID</code> exists. Foreach Gridview row, i am trying to use the statement like the following in C# using Asp.Net.</p>

<pre><code>foreach (GridViewRow row in grdFavoriteMerchant.Rows)
    {
        if (grdFavoriteMerchant.DataKeys[row.RowIndex]["Order_SelectionID"].ToString() != "")
        {
</code></pre>

<p>If <code>Order_SelectionID</code> exists and not a <code>NUll</code> or zero, i will have to "Insert", else an "Update". </p>

<p>This statement gives me an exception</p>

<blockquote>
  <p>"Object cannot be cast from DBNull to other types."</p>
</blockquote>

<p>everytime when i am supposed to use an Insert. How can i correct it?</p>
