Click here to Skip to main content
15,921,941 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
SQL
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);

I want to one more where condition i.e. WHERE FromSTN =@Branch".tell me how to do this
Posted

You need to use an AND clause[^] for this requirement.

It is always a good idea to use command parameters[^] rather than directly using variables in your query.
 
Share this answer
 
Note: use parameterized query/ stored procedure instead of inline query to avoid SQL Injection.

Just add with AND at the last like
C#
WHERE DocketNo ='" + strDocketNo + "' AND FromSTN =@Branch";

Now your code snippet should look like
C#
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
C#
//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 :)
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900