Hi,
The DataGridView Value property will return the object that is contains so if have assigned a Boolean type object to a cell, it will return that Boolean object when asked, you wouldn't need to convert it back to Boolean again.
I assume that you not used proper typed objects for the data binding i.e. where a "True/False" property typed as bool not string. However, if you have used correct types it is good. If not, it is more likely in your case, you would be using everything as string; then you must also check that the string object you are parsing around is not null.
So, in this case if the value is not null parse the string of that object, if it is null then set as empty:
for(int i =0;i<dgv_session.rowcount;i++)>
{
if (DGv_Session.Rows[i].Cells[1].Value != null)
{
if (Convert.ToBoolean(DGv_Session.Rows[i].Cells[1].Value))
{
sql = "insert into Tb_Session_Structure ([Cmn_Minor_code],[Days],[Session1],[Session2],[Session3],[Session4])";
sql = sql + " values('" + cb_Course_Code.Text + "', '"
+ (DGv_Session.Rows[i].Cells[0].Value != null) ? DGv_Session.Rows[i].Cells[0].Value.ToString() : "" + "',"
+ (DGv_Session[1, i].Value != null) ? DGv_Session[1, i].Value.ToString() : "" + ","
+ (DGv_Session[2, i].Value != null) ? DGv_Session[2, i].Value.ToString() : "" + ","
+ (DGv_Session[3, i].Value != null) ? DGv_Session[3, i].Value.ToString() : "" + ","
+ (DGv_Session[4, i].Value != null) ? DGv_Session[4, i].Value.ToString() : "" + ")";
GFun.Error = "";
GFun.InsertAccessData(sql);
if (GFun.Error.ToString() != "")
{
MessageBox.Show(GFun.Error.ToString(), "Error");
return;
}
GFun.OleDbCon.Close();
MessageBox.Show("Record Inserted Successfully");
}
}
}
I hope this helps.
Regards
Jegan