Note that there are some explanatory texts on larger screens.

plurals
  1. POIF condition statement that write in between sql in asp.net C#
    text
    copied!<p>i have wrote a if condition statement in C# with SQL code to update , delete and insert the data.</p> <p>i have facing the problem is the data will not be delete from the table.</p> <p>The condition is if the Qty is null or 0 then delete from the db table, kindly advise, thank you. </p> <pre><code>public void insertData(string str1, string str2, string str3, string str4, string str5, string str6, string str7, string str8, string str9, string str10, string str11, string str12) { string Qty = Inv_Qty.Text; string Inv_ID = WMItem.SelectedValue; string FromLoc = Inv_FromLoc.SelectedValue; SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["CIMProRPT01ConnectionString"].ConnectionString); con.Open(); string UpdateWMMRSQL = "UPDATE [CIMProRPT01].[dbo].[OTH_INV_QTY_LOC] SET INV_QTY = INV_QTY - '" + Qty + "' WHERE INV_ID = '" + Inv_ID + "' AND INV_LOCATION = '" + FromLoc + "' "; string sql = "INSERT INTO OTH_INV_TRANSACTION (INV_TRANS_ID,INV_ID,INV_TRANS_LOCATION,INV_TRANS_QTY,INV_TRANS_REQUESTOR,INV_TRANS_REFNO,INV_TRANS_REMARK,INV_REASON_ID,INV_REASON_REMARK,INV_CREATE_DATE,INV_CREATE_USER,INV_FROMLOC) VALUES ('" + str1 + "','" + str2 + "','" + str3 + "','" + str4 + "','" + str5 + "','" + str6 + "','" + str7 + "','" + str8 + "','" + str9 + "','" + str10 + "','" + str11 + "','" + str12 + "')"; SqlCommand cmd1 = new SqlCommand(UpdateWMMRSQL, con); SqlCommand cmd2 = new SqlCommand(sql, con); cmd1.ExecuteNonQuery(); cmd2.ExecuteNonQuery(); con.Close(); if (Qty == "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 = '" + FromLoc + "' "; SqlCommand cmddelete = new SqlCommand(DeleteWMMRSQL, con2); cmddelete.ExecuteNonQuery(); con2.Close(); } } </code></pre>
 

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