WFA_psychometric_chart.Form1_main.UpdateComfortZoneValue C# (CSharp) Method

UpdateComfortZoneValue() public method

public UpdateComfortZoneValue ( string id, string name, double min_temp, double max_temp, double min_hum, double max_hum, Color color ) : void
id string
name string
min_temp double
max_temp double
min_hum double
max_hum double
color Color
return void
        public void UpdateComfortZoneValue(string id, string name, double min_temp, double max_temp, double min_hum, double max_hum, Color color)
        {

            //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;";

            using (SQLiteConnection connection = new SQLiteConnection(connString))
            {
                connection.Open();
                //SQLiteDataReader reader = null;
                string sql_string = "UPDATE " + tableName + "   set  name =@name ,  min_temp=@min_t, max_temp=@max_t, min_hum=@min_h, max_hum=@max_h , colorValue=@color  where id  =@id ";

                //  "update  " + tableName + "(id,name,min_temp,max_temp,min_hum,max_hum,colorValue) VALUES(@id,@name,@min_t,@max_t,@min_h,@max_h,@color)";
                SQLiteCommand command = new SQLiteCommand(sql_string, connection);
                command.CommandType = CommandType.Text;
                command.Parameters.AddWithValue("@id", id);
                command.Parameters.AddWithValue("@name", name);
                command.Parameters.AddWithValue("@min_t", min_temp.ToString());
                command.Parameters.AddWithValue("@max_t", max_temp.ToString());
                command.Parameters.AddWithValue("@min_h", min_hum.ToString());
                command.Parameters.AddWithValue("@max_h", max_hum.ToString());
                command.Parameters.AddWithValue("@color", ColorTranslator.ToHtml(color));
                command.ExecuteNonQuery();
            }


        }

Usage Example

 private void btn_update_Click(object sender, EventArgs e)
 {
     //now we can update at this point the previous values.
     if (tb_name.Text != "")
     {
         if (tb_mintemp.Text != "" && tb_maxtemp.Text != "" && tb_minhum.Text != "" && tb_maxhum.Text != "")
         {
             //we need to grab the value and insert it
             double minT = double.Parse(tb_mintemp.Text);
             double maxT = double.Parse(tb_maxtemp.Text);
             double minH = double.Parse(tb_minhum.Text);
             double maxH = double.Parse(tb_maxhum.Text);
             string name = tb_name.Text;
             Color  c    = btn_color.BackColor;
             string id   = bs.listComfortZoneDetail[comboBox2.SelectedIndex].id;
             // bs.InsertComfortZoneValue(name, minT, maxT, minH, maxH, c);
             bs.UpdateComfortZoneValue(id, name, minT, maxT, minH, maxH, c);
             MessageBox.Show("Value updated succefully");
             //NOW LEST REFRESH THE FORM
             refreshAfterEdit();
         }
         else
         {
             MessageBox.Show("Please fill the temperature and humidity accurately");
         }
     }
     else
     {
         MessageBox.Show("Enter the name of the comfortzone");
     }
 }
Form1_main