Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>Problem 1:</strong> you are only checking wether <code>Qty</code> is <code>Zero</code> or not but as per your requirement you need to also check for <code>null</code> ,<code>Whitespace</code> and <code>Empty</code> aswell.</p> <p><strong>Solution 1:</strong> you can use <code>String.IsNullOrWhiteSpace()</code> function to check wether given <code>String</code> is <code>NULL</code> or <code>WhiteSpace</code> or <code>EMPTY</code>.</p> <p>Replace This:</p> <pre><code>if (Qty == "0") </code></pre> <p>with This:</p> <pre><code>if (String.IsNullOrWhiteSpace(Qty) || Qty.Trim().Equals("0")) </code></pre> <p><strong>Problem 2:</strong> you have enclosed single quotes around <code>INT</code> Column <code>INV_ID</code> . </p> <p><strong>Solution 2:</strong> you do not need to enclose <code>single quotes</code> around the <code>INT</code> columns.</p> <p>Replace this:</p> <pre><code>string DeleteWMMRSQL = "DELETE FROM [CIMProRPT01].[dbo].[OTH_INV_QTY_LOC] WHERE INV_ID = '" + Inv_ID + "' AND INV_LOCATION = '" + FromLoc + "' "; </code></pre> <p>With this:</p> <pre><code>string DeleteWMMRSQL = "DELETE FROM [CIMProRPT01].[dbo].[OTH_INV_QTY_LOC] WHERE INV_ID = " + Inv_ID + " AND INV_LOCATION = '" + FromLoc + "' "; </code></pre> <p><strong>Suggestion :</strong> your query is open to <code>SQL injection attacks</code>, i would suggest you to use <code>parameterised sql queries</code> to avoid them.</p> <p><strong>Delete Code:</strong> Using <code>parameterised queries</code></p> <pre><code> if (String.IsNullOrWhiteSpace(Qty) || Qty.Trim().Equals("0")) { SqlConnection con2 = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["CIMProRPT01ConnectionString"].ConnectionString); con2.Open(); string DeleteWMMRSQL = "DELETE FROM [CIMProRPT01].[dbo].[OTH_INV_QTY_LOC] WHERE INV_ID = @INV_ID AND INV_LOCATION = @INV_LOCATION"; SqlCommand cmddelete = new SqlCommand(DeleteWMMRSQL, con2); cmddelete.Parameters.AddWithValue("@INV_ID",Inv_ID); cmddelete.Parameters.AddWithValue("@INV_LOCATION",FromLoc); cmddelete.ExecuteNonQuery(); con2.Close(); } </code></pre>
    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