コード例 #1
0
        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            SqlConnection con = new SqlConnection(conStr);

            con.Open();
            if (e.RowIndex > -1)
            {
                if (e.ColumnIndex == 0)
                {
                    EditGroupEvaluation edit = new EditGroupEvaluation();
                    edit.txt_grpid.Text = this.dataGridView1.CurrentRow.Cells[2].Value.ToString();

                    edit.txt_evalid.Text          = this.dataGridView1.CurrentRow.Cells[3].Value.ToString();
                    edit.txt_obtainmark.Text      = this.dataGridView1.CurrentRow.Cells[4].Value.ToString();
                    edit.dtp_evaluation_date.Text = this.dataGridView1.CurrentRow.Cells[5].Value.ToString();
                    // edit.txt_email.Text = this.dataGridView1.CurrentRow.Cells[6].Value.ToString();

                    edit.ShowDialog();
                }
                else if (e.ColumnIndex == 1)
                {
                    DataGridViewRow row = this.dataGridView1.Rows[e.RowIndex];
                    // string t = "DELETE FROM GroupEvaluation where GroupId = '" + row.Cells[2].Value + "' And EvaluationId = '" + row.Cells[3].Value + "';";

                    string t = "DELETE FROM GroupEvaluation where GroupId = '" + row.Cells[2].Value + "' And EvaluationId = '" + row.Cells[3].Value + "';";


                    SqlCommand cmd = new SqlCommand(t, con);
                    cmd.ExecuteNonQuery();
                    MessageBox.Show("Congrats! Record Recorded");
                    SqlDataAdapter sql     = new SqlDataAdapter("SELECT * from GroupEvaluation", con);
                    DataTable      datatab = new DataTable();
                    sql.Fill(datatab);
                    dataGridView1.DataSource = datatab;
                    con.Close();
                }
                AllGroupEvaluations std = new AllGroupEvaluations();
                this.Hide();
                std.Show();
            }
        }
コード例 #2
0
 private void btn_evaluate_Click(object sender, EventArgs e)
 {
     try
     {
         SqlConnection con = new SqlConnection(conStr);
         con.Open();
         if (con.State == ConnectionState.Open)
         {
             String     q   = "INSERT INTO GroupEvaluation(GroupId,EvaluationId,ObtainedMarks,EvaluationDate)VALUES((select Id from [Group] where [Group].Id = '" + com_gro_id.Text + "'),('" + Convert.ToInt32(com_evalid.Text) + "'),('" + Convert.ToInt32(txt_obtainmark.Text) + "'),('" + Convert.ToDateTime(dtp_evaluation_date.Value) + "'));";
             SqlCommand cmd = new SqlCommand(q, con);
             cmd.ExecuteNonQuery();
             MessageBox.Show("Data Inserted Successfully");
         }
         AllGroupEvaluations std = new AllGroupEvaluations();
         this.Hide();
         std.Show();
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }