for (int j = 0; j < dgvcheckin.Rows.Count; j++)
{
if (Convert.ToBoolean(dgvcheckin.Rows[j].Cells["RoomNo"].Value) == null)
{
dgvcheckin.Rows.Remove(dgvcheckin.CurrentRow);
}
}
int NumberofRooms=1;
for (int j = 0; j < dgvcheckin.Rows.Count;j++ )
{
if (dgvcheckin.Rows[j].Cells["RoomNo"].Value.ToString() != "" || dgvcheckin.Rows[j].Cells["RoomNo"].Value != null)
{
NumberofRooms=+NumberofRooms;
}
}
This is my code when compiler check the datagridview room cell it give back null then it going to exception and skip the remaining the code any body have any idea....
This is my code when compiler check the datagridview room cell it give back null then it going to exception and skip the remaining the code any body have any idea....

Michal HabalcikPosted Dec 5, 2014, 6:41 AM
This condition
dgvcheckin.Rows[j].Cells["RoomNo"].Value.ToString() != "" || gvcheckin.Rows[j].Cells["RoomNo"].Value != null
can be written as String.IsNullOrEmpty(dgvcheckin.Rows[j].Cells["RoomNo"].Value)
mohammed shamsheerPosted Dec 5, 2014, 6:55 AM
mohammed shamsheerPosted Dec 5, 2014, 6:53 AM
mohammed shamsheerPosted Dec 5, 2014, 6:37 AM
Michal HabalcikPosted Dec 5, 2014, 6:28 AM
Here is the documentation for Convert.ToBoolean:
http://msdn.microsoft.com/en-us/library/wh2c31dd%28v=vs.110%29.aspx?cs-save-lang=1&cs-lang=csharp#code-snippet-1
Michal HabalcikPosted Dec 5, 2014, 6:18 AM
for (int j = 0; j < dgvcheckin.Rows.Count; j++)
{
if (dgvcheckin.Rows[j].Cells["RoomNo"].Value != null && Convert.ToBoolean(dgvcheckin.Rows[j].Cells["RoomNo"].Value) == null)
{
dgvcheckin.Rows.Remove(dgvcheckin.CurrentRow);
}
}
int NumberofRooms=1;
for (int j = 0; j < dgvcheckin.Rows.Count;j++ )
{
if (dgvcheckin.Rows[j].Cells["RoomNo"].Value != null || dgvcheckin.Rows[j].Cells["RoomNo"].Value.ToString() != "" )
{
NumberofRooms=+NumberofRooms;
}
}
Kunal VaishyaPosted Dec 5, 2014, 5:44 AM
Check null value before Convert the boolean value,because null value can not be converted in any type.
Regards,
kingskunal.