private void buttonEliminar_Click(object sender, EventArgs e) { DialogResult dr = MessageBox.Show("¿Desea eliminar este trabajo?" , "Confirmar Calificación", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (dr == DialogResult.Yes) { con.Open(); con.Command("delete from assignment_student where idAssignment = " + idAssignment + ";"); con.Command("delete from Assignment where idAssignment = " + idAssignment + ";"); con.Close(); parent.fillDataGridAssignment(); this.Close(); } }
private void SendHomework(string title, string desc, string val) { string sql = @"insert into assignment(weight,name,description,idCourse) values({0},'{1}','{2}',{3});"; sql = String.Format(sql, val, title, desc, idCourse); DataTable dt; try { con.Open(); con.Command(sql); dt = con.SelectTable("select idStudent from course_student where idCourse=" + idCourse + ";"); string idAss = con.SelectSingle("select idAssignment from assignment where idAssignment=(Select max(idAssignment) from assignment);"); sql = "insert into assignment_student(idassignment,idstudent) values({0},{1});"; foreach (DataRow r in dt.Rows) { con.Command(string.Format(sql, idAss, r.ItemArray[0].ToString())); } con.Close(); } catch (System.Data.SQLite.SQLiteException err) { MessageBox.Show(err.Message.ToString()); } catch (System.IndexOutOfRangeException err) { MessageBox.Show("Error en el foreach\n" + err.Message); } finally { con.Close(); } parent.fillDataGridAssignment(); this.Close(); }