Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The problem stated by your error message is probably on one of the lines that try to convert the value in the textboxes to a short integer. Without any check, the value typed by your user could be anything but a number and you get this error message (for example, if you user leaves the textboxes empty). </p> <p>You should try to check if the textboxes content could be converted to a valid short integer using <a href="http://msdn.microsoft.com/en-us/library/system.int16.tryparse.aspx" rel="nofollow">TryParse</a> before attempting to execute the query</p> <pre><code>int ordered; if(!int16.TryParse(txtQtyOrdered.Text, out ordered)) { MessageBox.Show("Invalid number for Ordered quantity"); return; } int orderID; if(!int16.TryParse(txtPONumber.Text, out orderID)) { MessageBox.Show("Invalid number for OrderId"); return; } int itemID; if(!int16.TryParse(txtItemNo.Text, out itemID)) { MessageBox.Show("Invalid number for ItemID"); return; } </code></pre> <p>At this point you could execute your calculation using the converted short integers and then write your query in this way (adding a space before the AND)</p> <pre><code> com.CommandText = "UPDATE PODetail SET BalanceQty="+ newbal.ToString() + " WHERE OrderID=" + orderID.ToString() + " AND ItemID=" + itemID.ToString(); </code></pre> <p>But the string concatenation of query text and user input is never advised as a good practice (in your case is harmless because if the conversion is successful you don't have to worry about Sql Injection, but don't take the habit to do it).<br> So the perfect way to write this query is through the use of a parametrized query</p> <pre><code> com.CommandText = "UPDATE PODetail SET BalanceQty=@newbal " + " WHERE OrderID=@orderID " + " AND ItemID= @itemID" com.Parameters.AddWithValue("@newbal", newBal); com.Parameters.AddWithValue("@orderID", orderID); com.Parameters.AddWithValue("@itemID", itemID); com.ExecuteNonQuery(); </code></pre> <p>As a good article on Parameterized query and why to use them, I suggest to <a href="http://www.codinghorror.com/blog/2005/04/give-me-parameterized-sql-or-give-me-death.html" rel="nofollow">read these old words</a> from Jeff Atwood</p>
 

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