Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Statments like <code>if (textBox4.Text == "" &amp;&amp; textBox2.Text == "")</code> means nothing at all, if you are not up to speed on what that particular part of the application is up to. In this case it seems as if they represent one value each, and that at least one of them should contain something for any operation to be legal. Studying the SQL statements suggests that <code>textBox2</code> is a quantity and <code>textBox4</code> is a price. First thing would be to change those control names into something more meaningful.</p> <p>Second, I'd wrap the checks into methods with more descriptive names:</p> <pre><code>private bool HasPriceValue() { return !string.IsNullOrEmpty(textBox4.Text); } private bool HasQuantityValue() { return !string.IsNullOrEmpty(textBox2.Text); } </code></pre> <p>Then you can rewrite the if-block as so:</p> <pre><code>if (!HasPriceValue() &amp;&amp; !HasQuantityValue()) { MessageBox.Show("No value entred for update."); } else { ConnectionClass.OpenConnection(); if (HasQuantityValue()) { SqlCommand cmd = new SqlCommand("update medicinerecord set quantity='" + textBox2.Text + "' where productid='"+comboBox1.Text+"'", ConnectionClass.OpenConnection()); cmd.ExecuteNonQuery(); } if (HasPriceValue()) { SqlCommand cmd = new SqlCommand("update myrecord set price='" + textBox4.Text + "' where productid='" + comboBox1.Text + "'", ConnectionClass.OpenConnection()); cmd.ExecuteNonQuery(); } ConnectionClass.CloseConnection(); } </code></pre> <p>This way you don't repeat the SQL queries in the code and it's fairly easy to read the code and understand what it does. The next step would be to rewrite the SQL queries to use parameters instead of concatenated strings (which opens your code for SQL injection attacks), <a href="https://stackoverflow.com/questions/6138301/how-can-i-refactor-this-method/6138413#6138413">as suggested by Darin</a>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload