放置第二个WHERE条件 [英] Putting A second WHERE condition
本文介绍了放置第二个WHERE条件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
string strUpdate = "Update CreateDocket set BranchCode = '" + strBranchCode + "', Date = '" + strDate + "', PinCode = '" + strPinCode + "', [To] = '" + strTo + "', ConrCode = '" + strConrCode + "', Consignee = '" + strConsignee + "', PKTS = '" + strPKTS + "',ActWt = '" + strActWt + "',ChargeWt = '" + strChargeWt + "', GrandTotal = '" + strGrandTotal + "', GoodsType = '" + strGoodsType + "', CODamount = '" + strCODamount + "', Basis = '" + strBasis + "', Mode = '" + strMode + "',ChallanNo = '" + strChallanNo + "',VehicleNo = '" + strVehicleNo + "',ChallanDate = '" + strChallanDate + "',Description = '" + strDescription + "', RChallanDate = '" + strRChallanDate + "', FromHub='" + strFromHub + "', ToHub='" + strToHub + "', Remarks='" + strRemarks + "' , Received2 = 'True' WHERE DocketNo ='" + strDocketNo + "'";
strSql.Append(strUpdate);
我想再多一个条件即WHERE FromSTN = @ Branch。我怎么做这个
I want to one more where condition i.e. WHERE FromSTN =@Branch".tell me how to do this
推荐答案
您需要使用AND
子句 [ ^ ]这个要求。
使用命令参数 [ ^ ]而不是直接使用变量您的查询。
You need to use anAND
clause[^] for this requirement.
It is always a good idea to use command parameters[^] rather than directly using variables in your query.
注意:使用参数化查询/存储过程而不是内联查询来避免SQL注入。
只需添加和最后喜欢
Note: use parameterized query/ stored procedure instead of inline query to avoid SQL Injection.
Just add with AND at the last like
WHERE DocketNo ='" + strDocketNo + "' AND FromSTN =@Branch";
现在你的代码片段看起来像
Now your code snippet should look like
string strUpdate = "Update CreateDocket set BranchCode = '" + strBranchCode + "', Date = '" + strDate + "', PinCode = '" + strPinCode + "', [To] = '" + strTo + "', ConrCode = '" + strConrCode + "', Consignee = '" + strConsignee + "', PKTS = '" + strPKTS + "',ActWt = '" + strActWt + "',ChargeWt = '" + strChargeWt + "', GrandTotal = '" + strGrandTotal + "', GoodsType = '" + strGoodsType + "', CODamount = '" + strCODamount + "', Basis = '" + strBasis + "', Mode = '" + strMode + "',ChallanNo = '" + strChallanNo + "',VehicleNo = '" + strVehicleNo + "',ChallanDate = '" + strChallanDate + "',Description = '" + strDescription + "', RChallanDate = '" + strRChallanDate + "', FromHub='" + strFromHub + "', ToHub='" + strToHub + "', Remarks='" + strRemarks + "' , Received2 = 'True' WHERE DocketNo ='" + strDocketNo + "' AND FromSTN =@Branch";
strSql.Append(strUpdate);
然后为参数增加值
then add value to the parameter
//add parameter to your command object
command.Parameters.Add(new SqlParameter("Branch", YourValue)); //provide value here
万一这没有用,请告诉我:))
In case this doesn't help, please let me know :)
这篇关于放置第二个WHERE条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文