WFA_psychometric_chart.Form1_main.DeleteComfortZoneData C# (CSharp) Method

DeleteComfortZoneData() public method

public DeleteComfortZoneData ( string id ) : void
id string
return void
        public void DeleteComfortZoneData(string id)
        {
            /*
            steps:1. Delete form the ..._comfort_zone_detail and then form _comfort_zone_chart_setting

            */

            //string idValue = GetGUID();
            string tableName = "tbl_" + selectedBuildingList[0].BuildingName + "_comfort_zone_detail";   // currentLineTableFromDB;
            string databasePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
            string databaseFile = databasePath + @"\db_psychrometric_project.s3db";
            string connString = @"Data Source=" + databaseFile + ";Version=3;";

            string tableName2 = "tbl_" + selectedBuildingList[0].BuildingName + "_chart_comfort_zone_setting";   // currentLineTableFromDB;

            using (SQLiteConnection connection = new SQLiteConnection(connString))
            {
                connection.Open();
                //SQLiteDataReader reader = null;
                string sql_string = "delete from  " + tableName + "  where id  =@id ";
                SQLiteCommand command = new SQLiteCommand(sql_string, connection);
                command.CommandType = CommandType.Text;
                command.Parameters.AddWithValue("@id", id);
                command.ExecuteNonQuery();


                string sql_string2 = "delete from  " + tableName2 + "  where comfort_zone_ID  =@id ";
                SQLiteCommand command2 = new SQLiteCommand(sql_string2, connection);
                command2.CommandType = CommandType.Text;
                command2.Parameters.AddWithValue("@id", id);
                command2.ExecuteNonQuery();

            }

        }

Usage Example

        private void btn_delete_Cl(object sender, EventArgs e)
        {
            //This one is for deletion operation
            int index = comboBox2.SelectedIndex;

            if (index >= 0)
            {
                //WE need to call the index value as well as send the id parameter
                //This will delete the value form both the comfortDetail and chartcomfortzonesetting table.
                DialogResult dialogResult = MessageBox.Show("are you sure you want to delete :" + bs.listComfortZoneDetail[index].name, "Delete", MessageBoxButtons.YesNo);
                if (dialogResult == DialogResult.Yes)
                {
                    bs.DeleteComfortZoneData(bs.listComfortZoneDetail[index].id);
                    MessageBox.Show("value deleted successfully");
                    //Refresh the values
                    refreshAfterEdit();
                }
            }
        }
Form1_main