hi,
here is my code i want to add some Sections to class based on combobox selected Text in to datatable
i want when its checked value should insert and when uncked value should delete
private void datagridclasssections_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
string All = comboaddclass.Text.ToString();
var senderGrid = (DataGridView)sender;
if (senderGrid.Columns[e.ColumnIndex] is DataGridViewCheckBoxColumn &&
e.RowIndex >= 0)
if (e.RowIndex == 0 && e.ColumnIndex!=null)
{
label2.Text = datagridclasssections.Rows[0].Cells[1].Value.ToString();
SqlConnection con = new SqlConnection();
con = new SqlConnection(connectionString);
{
con.Open();
SqlCommand cmd = new SqlCommand("insert into Tbl_tempClass (Class,Section) values ('" + comboaddclass.Text + "','" + label2.Text + "')", con);
cmd.CommandType = CommandType.Text;
SqlDataReader reader = null;
reader = cmd.ExecuteReader();
}
}
//-----------------------------------------------------------------------------------------------------//
if (e.RowIndex == 1)
{
label3.Text = datagridclasssections.Rows[1].Cells[1].Value.ToString();
SqlConnection con1 = new SqlConnection();
con1 = new SqlConnection(connectionString);
{
con1.Open();
SqlCommand cmd = new SqlCommand("insert into Tbl_tempClass (Class,Section) values ('" + comboaddclass.Text + "','" + label2.Text + "')", con1);
cmd.CommandType = CommandType.Text;
SqlDataReader reader = null;
reader = cmd.ExecuteReader();
}