validating checkbox which are not checked in the datagridview those record should not be save in the database.
Save code as follows;
for (int i = 0; i < DGv_Session.RowCount; i++)
{
try
{
if (DGv_Session[1, i].Value != null && DGv_Session[1, i].Value != "" && DGv_Session[2, i].Value != null && DGv_Session[2, i].Value != "" && DGv_Session[3, i].Value != null && DGv_Session[3, i].Value != "" && DGv_Session[4, i].Value != null && DGv_Session[4, i].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.ToString() + "',
" + (Convert.ToBoolean(DGv_Session[1, i].Value) == true).ToString() + ",
" + (Convert.ToBoolean(DGv_Session[2, i].Value) == true).ToString() + ",
" + (Convert.ToBoolean(DGv_Session[3, i].Value) == true).ToString() + ",
" + (Convert.ToBoolean(DGv_Session[4, i].Value) == true).ToString() + ")";
GFun.Error = "";
GFun.InsertAccessData(sql);
if (GFun.Error.ToString() != "")
{
MessageBox.Show(GFun.Error.ToString(), "Error");
return;
}
GFun.OleDbCon.Close();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString(), "Error");
return;
}
}
I am validating check box which are not checked in the datagridview that value not to be saved in the database.
Days 1 2
1 checkboxunchecked checkboxunchecked
2 checkboxchecked checkboxchecked
after enters the above records into the database and click the save button.
In the database records show as follows;
Days 1 2
1 checkboxunchecked checkboxunchecked
2 checkboxchecked checkboxchecked
but i want which checkbox which which are not checked in the datagridview do not be saved in the database.
I want the final output as follows after made entries and click the save button records in the database as follows;
Final ouput as follows;
Days 1 2
2 checkboxchecked checkboxchecked