when i multiply two columns in gridview in c# the error is Object cannot be cast from DBNull to other types.
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Sanjeeb LenkaPosted Jul 30, 2013, 2:13 PM
decimal sum = 0.00m;
decimal s, s1;
for (int i = 0; i < tbl_main_subDataGridView.Rows.Count; i++)
{
if (tbl_main_subDataGridView.CurrentRow.Cells[4].Value != DBNull.Value)
s = Convert.ToDecimal(tbl_main_subDataGridView.CurrentRow.Cells[4].Value);
else
s = 0.00m;
if (tbl_main_subDataGridView.CurrentRow.Cells[5].Value != DBNull.Value)
s1 = Convert.ToDecimal(tbl_main_subDataGridView.CurrentRow.Cells[5].Value);
else
s1 = 0.00m;
decimal s13 = s1 * s;
tbl_main_subDataGridView.CurrentRow.Cells[6].Value = s13;
}
hoshiar aliPosted Jul 30, 2013, 2:46 PM
Regards
Hoshiar Ali
Iftikar HussainPosted Jul 30, 2013, 1:25 PM
Regards,
Iftikar
hoshiar aliPosted Jul 30, 2013, 12:52 PM
decimal sum = 0.00m;
decimal s = Convert.ToInt32(tbl_main_subDataGridView.CurrentRow.Cells[4].Value);
decimal s1 = Convert.ToInt32(tbl_main_subDataGridView.CurrentRow.Cells[5].Value);
Iftikar HussainPosted Jul 30, 2013, 12:21 PM
You need to check null before multiply. Please share your code.
Regards,
Iftikar