title: Updating stock in run time while adding items to bill with C#
body: <p>I'm developing a billing application with C# windows ms access back-end. In the billing task i'm adding purchased items to bill and the same time i'm updating the stock of that item. Items stock got updated successfully in table.But when i load the updated stock in my textBox it requires an extra event to populate the textBox. I'm performing all the above task in a single button click. When adding the next item to bill and i press the add button...then the updated stock get loaded to the textbox of previous item. How can i load the textBox(in real Time) with current upadated stock when I add items to bill with a single button click with extra event?
  what im doing is--</p>
  
  <pre><code>    private void button4_Click(object sender, EventArgs e)
      {
          calamnt();
          string ddd = textBox6.Text;
          if (textBox4.Text.Length != 0)
          {
  
  
                  if (textBox14.Text.Length == 0)
                  {
                      string bid = getunique();
                      textBox14.Text = bid;
                  }
              if (Convert.ToDouble(textBox4.Text) &lt;= 0)
              {
                  MessageBox.Show("No more stock");
              }
              else
              {
                  bill();
                  ddr.Clear();
                  // button4.Enabled = true;
                  load_bill();
                  stock_update();
                  textBox6.Enabled = false;
                  unit_total += Convert.ToDouble(textBox3.Text);
                  // button4.Enabled = false;
                  // dataGridView1.Columns.Clear();
  
  
              }
                  //MessageBox.Show(code_total.ToString());
  
          }
          else
          {
              MessageBox.Show("Please enter a phone no");
          } 
  </code></pre>
  
  <p>//code for adding item to bill</p>
  
  <pre><code>calculate_purchase_amount();
          double qty = Convert.ToDouble(textBox5.Text);
          double camnt = Convert.ToDouble(textBox3.Text);
         // double disc = Convert.ToDouble(textBox16.Text);
          double mr = Convert.ToDouble(textBox1.Text);
         // actual_amount = Convert.ToDouble(textBox6.Text) - Convert.ToDouble(textBox16.Text);
          OleDbConnection conn = new OleDbConnection();
          conn.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + sd + "bowoni.accdb";
         string add_item = "insert into purchase(bill_id,customer_name,item_name,expire,batch,unit_price,qty,mrp,disc,amount)values('" + textBox14.Text + "','" + comboBox4.Text + "','" + comboBox2.Text + "','" + textBox19.Text + "','" + textBox18.Text + "','" + camnt + "','" + qty + "','" + mr + "','" + disc + "','" + actual_amount + "')";
          OleDbCommand cmdbill = new OleDbCommand(add_item, conn);
          conn.Open();
          int xxt = cmdbill.ExecuteNonQuery();
          System.Threading.Thread.Sleep(500);
          if (xxt &gt; 0)
          {
              flag = true;
             // MessageBox.Show("Data inserted successfuly");
          }
          else
          {
              MessageBox.Show("Error");
          }
  </code></pre>
  
  <p>//stock update</p>
  
  <pre><code> double new_stock = Convert.ToDouble(textBox4.Text) - Convert.ToDouble(textBox5.Text);
          double new_tot_purchase = new_stock * unit_pri;
          OleDbConnection con = new OleDbConnection();
          con.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + sd + "bowoni.accdb";
          string updatestkfrom_bill = "update item set stock='" + new_stock + "',total_it='"+new_tot_purchase+"'where item_name='" + comboBox2.Text + "'";
          OleDbCommand cmd = new OleDbCommand(updatestkfrom_bill, con);
          con.Open();
          Thread.Sleep(400);
          int xxt = cmd.ExecuteNonQuery();
          if (xxt &gt; 0)
          {
              MessageBox.Show("STock updated");
              DataTable ds = new DataTable();
  
               comboBox2.Items.Clear();
              if (comboBox2.Items.Count &gt; 0)
              {
                  OleDbDataReader odr;
                  OleDbConnection conn = new OleDbConnection();
                  conn.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + sd + "bowoni.accdb";
  
                  conn.Open();
                  string combo = "select * from item where item_name='" + comboBox2.Text + "'";
                  OleDbCommand cmd4 = new OleDbCommand(combo, conn);
                  odr = cmd4.ExecuteReader();
  
                  ds.Load(odr);
  
                  Thread.Sleep(500);
                  foreach (DataRow row in ds.Rows)
                  {
                      // dataGridView1.DataSource = dt;
  
                      textBox4.Text = row[0]["stock"].ToString();
  
                  }
  
  
          }
  </code></pre>