private void btnYesClick(object sender, EventArgs e)
 {
     connection = new MyConnection();
     try
     {
         connection = new MyConnection();
         com = new SqlCommand("DELETE FROM KTR WHERE id=@id");
         com.Parameters.AddWithValue("@id", id);
         connection.executeMyQuery(com);
         connection.closeMyConnection();
         this.Close();
     }
     catch (SqlException ex)
     {
         connection.closeMyConnection();
         throw ex;
     }
 }
 private void btnGetClick(object sender, EventArgs e)
 {
     lblInfo.Text = "";
     try
     {
         myConnection = new MyConnection();
         dataReader = myConnection.executeMyQuery("SELECT * FROM KTR ORDER BY id DESC");
         dataGridView.Rows.Clear();
         while (dataReader.Read())
         {
             readSingleRow((IDataRecord)dataReader);
         }
         myConnection.closeMyConnection();
     }
     catch (SqlException ex)
     {
         lblInfo.Text = ex.Message;
         myConnection.closeMyConnection();
     }
 }
        private void btnAddClick(object sender, EventArgs e)
        {
            switch(type)
            {
                case 1: // adding row

                    if (!checkBox.Checked) { del = 0; } else { del = 1; }
                    try
                    {
                        myConnection = new MyConnection();
                        if (txtName.Text.Length < 3 | txtName.Text.Length > 32)
                        {
                            lblInfo.Text = "Не коректное значение!";
                            return;
                        }
                        command = new SqlCommand("INSERT INTO KTR (Name,ShortName,Del,Stamp,created,creator,changed,changer) VALUES (@Name,@ShortName,@Del,@Stamp,@created,@creator,@changed,@changer)");
                        command.Parameters.AddWithValue("@Name", txtName.Text);
                        command.Parameters.AddWithValue("@ShortName", txtShort.Text);
                        command.Parameters.AddWithValue("@changer", txtChanger.Text);
                        command.Parameters.AddWithValue("@Del", del);
                        command.Parameters.AddWithValue("@Stamp", DateTime.Now);
                        command.Parameters.AddWithValue("@created", DateTime.Now);
                        command.Parameters.AddWithValue("@changed", DateTime.Now);
                        command.Parameters.AddWithValue("@creator", "user");
                        myConnection.executeMyQuery(command);
                        myConnection.closeMyConnection();
                        this.Close();
                    }
                    catch (SqlException ex)
                    {
                        this.Close();
                        throw ex;
                    }
                    break;
                case 2: // updating row
                    if (!checkBox.Checked) { del = 0; } else { del = 1; }

                    try
                    {
                        myConnection = new MyConnection();
                        if (txtName.Text.Length < 3 | txtName.Text.Length > 32 | txtID.Text.Length < 0)
                        {
                            lblInfo.Text = "Не коректное значение!";
                            return;
                        }
                        command = new SqlCommand("UPDATE KTR SET Name=@Name,ShortName=@ShortName,Del=@Del,Stamp=@Stamp,creator=@creator,changed=@changed,changer=@changer WHERE id=@id");
                        command.Parameters.AddWithValue("@id", txtID.Text);
                        command.Parameters.AddWithValue("@Name", txtName.Text);
                        command.Parameters.AddWithValue("@ShortName", txtShort.Text);
                        command.Parameters.AddWithValue("@changer", txtChanger.Text);
                        command.Parameters.AddWithValue("@Del", del);
                        command.Parameters.AddWithValue("@Stamp", DateTime.Now);
                        command.Parameters.AddWithValue("@created", DateTime.Now);
                        command.Parameters.AddWithValue("@changed", DateTime.Now);
                        command.Parameters.AddWithValue("@creator", "user");
                        myConnection.executeMyQuery(command);
                        myConnection.closeMyConnection();
                        this.Close();

                    }
                    catch (SqlException ex)
                    {
                        this.Close();
                        throw ex;
                    }
                    break;
            }
        }