Npgsql.NpgsqlCommand.Cancel C# (CSharp) Method

Cancel() public method

Attempts to cancel the execution of a NpgsqlCommand.
This Method isn't implemented yet.
public Cancel ( ) : void
return void
        public override void Cancel()
        {
            NpgsqlEventLog.LogMethodEnter(LogLevel.Debug, CLASSNAME, "Cancel");

            try
            {
                // get copy for thread safety of null test
                NpgsqlConnector connector = Connector;
                if (connector != null)
                {
                    connector.CancelRequest();
                }
            }
            catch (IOException)
            {
                Connection.ClearPool();
            }
            catch (NpgsqlException)
            {
                // Cancel documentation says the Cancel doesn't throw on failure
            }
        }

Usage Example

Example #1
0
        /*
        function name AddStudents_Click
        inputs: query
        outputs: add student studying lesson and cancel student studying lesson
        errors:
        */
        private void AddStudents_Click(object sender, EventArgs e)
        {
            string str = "Uid=postgres; Password=123; server=localhost; port=5432; Database=classmanagement;";
            NpgsqlConnection conn = new NpgsqlConnection(str);
            conn.Open();

            foreach (DataGridViewRow dr in dataGridView1.Rows)
            {
                int n = dr.Index;
                if (dr.Cells[0].Value != null)
                {

                    String insert = "";

                    String select1 = "SELECT studentname FROM attendance WHERE studentname='" + dataGridView1.Rows[n].Cells[1].Value + "'AND subjectname='" + comboBox1.Text + "'";
                    NpgsqlCommand select_command1 = new NpgsqlCommand(select1, conn);
                    NpgsqlDataReader read = select_command1.ExecuteReader();
                    if (read.Read())
                    {
                        MessageBox.Show("Error message", "error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    else
                    {
                        insert = "INSERT into attendance VALUES('" + dataGridView1.Rows[n].Cells[2].Value + "','" + dataGridView1.Rows[n].Cells[3].Value + "','" + comboBox1.Text + "')";
                        NpgsqlCommand command = new NpgsqlCommand(insert, conn);
                        command.ExecuteNonQuery();
                        command.Cancel();
                        String select = "SELECT name,start_time,start_minute,finish_time,finish_minute FROM subject WHERE name='" + comboBox1.Text + "'";
                        NpgsqlCommand select_command = new NpgsqlCommand(select, conn);
                        NpgsqlDataReader reader1 = select_command.ExecuteReader();
                        NpgsqlCommand baba = new NpgsqlCommand();
                        if (reader1.Read())
                        {
                            int num1 = Convert.ToInt32(reader1[1]);
                            int num2 = Convert.ToInt32(reader1[2]);
                            int num3 = Convert.ToInt32(reader1[3]);
                            int num4 = Convert.ToInt32(reader1[4]);
                            String ins = "INSERT into startfinish VALUES('" + comboBox1.Text.ToString() + "','" + dataGridView1.Rows[n].Cells[2].Value + "','" + dataGridView1.Rows[n].Cells[3].Value + "','" + num1 + "','" + num2 + "','" + num3 + "','" + num4 + "')";
                            baba = new NpgsqlCommand(ins, conn);

                        }
                        reader1.Close();
                        baba.ExecuteNonQuery();

                        insert = "INSERT into homework VALUES('" + dataGridView1.Rows[n].Cells[2].Value + "','" + dataGridView1.Rows[n].Cells[3].Value + "','" + comboBox1.Text.ToString() + "')";
                        NpgsqlCommand comm = new NpgsqlCommand(insert, conn);
                        comm.ExecuteNonQuery();

                        insert = "INSERT into grade VALUES('" + comboBox1.Text.ToString() + "','" + dataGridView1.Rows[n].Cells[2].Value + "','" + dataGridView1.Rows[n].Cells[3].Value + "')";
                        NpgsqlCommand comm1 = new NpgsqlCommand(insert, conn);
                        comm1.ExecuteNonQuery();

                        //MessageBox.Show("success.");
                    }
                    read.Close();
                }
                else
                {
                    String delete = "DELETE FROM attendance WHERE studentname='" + dataGridView1.Rows[n].Cells[2].Value + "' AND subjectname='"+comboBox1.Text+"'";
                    NpgsqlCommand comm = new NpgsqlCommand(delete, conn);
                    comm.ExecuteNonQuery();

                    delete = "DELETE FROM startfinish WHERE student_name='" + dataGridView1.Rows[n].Cells[2].Value + "' AND lesson_name='"+comboBox1.Text+"'";
                    NpgsqlCommand comm1 = new NpgsqlCommand(delete, conn);
                    comm1.ExecuteNonQuery();

                    delete = "DELETE FROM homework WHERE studentname='" + dataGridView1.Rows[n].Cells[2].Value + "' AND subjectname='" + comboBox1.Text + "'";
                    NpgsqlCommand comm2 = new NpgsqlCommand(delete, conn);
                    comm2.ExecuteNonQuery();

                    delete = "DELETE FROM grade WHERE student_name='" + dataGridView1.Rows[n].Cells[2].Value + "' AND lesson='" + comboBox1.Text + "'";
                    NpgsqlCommand comm3 = new NpgsqlCommand(delete, conn);
                    comm3.ExecuteNonQuery();
                }

            }
            conn.Close();
        }
All Usage Examples Of Npgsql.NpgsqlCommand::Cancel