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 Order_SelectionID exists. Foreach Gridview row, i am trying to use the statement like the following in C# using Asp.Net.
foreach (GridViewRow row in grdFavoriteMerchant.Rows)
{
if (grdFavoriteMerchant.DataKeys[row.RowIndex]["Order_SelectionID"].ToString() != "")
{
If Order_SelectionID exists and not a NUll or zero, i will have to “Insert”, else an “Update”.
This statement gives me an exception
“Object cannot be cast from DBNull to other types.”
everytime when i am supposed to use an Insert. How can i correct it?
Why not compare directly to
DBNull.Value?