Design as follows;
Course Code Combobox
Datagridview
In Datagridview as follows;
Days 1 2 3 4
1 check box check box check box check box
2 check box check box check box check box
3 check box check box check box check box
4 check box check box check box check box
In the rum mode, I select the course and in the datagridiview select the checkbox and save.
Then I again choose another course and in the datagridveiw select the checkbox and save.
My save code as follows;
for (int i = 0; i < DGv_Session.RowCount; i++)
{
try
{
if (DGv_Session.Rows[i].Cells[1].Value != null && DGv_Session.Rows[i].Cells[2].Value != null && DGv_Session.Rows[i].Cells[3].Value != null && DGv_Session.Rows[i].Cells[4].Value != null)
{
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;
}
}
MessageBox.Show("Record Inserted Successfully","Record Inserted",MessageBoxButtons.OK,MessageBoxIcon.Information);
When I save in the database, suppose I save the two course in the database.
Only one course save in the database.
The second course not saved in the database.
What is the problem in my above code?
Please help me.
Regards,
Narasiman P.
Note it is windows applciation.