Freelancer
Freelancer

Reputation: 9074

Delete query not working

I am using linq to delete data from database. I googled, and made query. I am using following query.

When i put debugger over this, its not showing any error. Its going fine. But when I check my database , record does not gets delete.

At the same time doing operation for insert:

 splitTradeDataContext db = new splitTradeDataContext();
                    tradeFile tlbTradeFile = new tradeFile();

 tlbTradeFile.TradeNo = TradeNo + "_A";
               tlbTradeFile.Status = Status;
               tlbTradeFile.Scrip_Code = Scrip_Code;
               tlbTradeFile.Inst_Type = Inst_Type;
               tlbTradeFile.Expirydate = Expirydate;
               tlbTradeFile.Strike_price = Strike_price;
               tlbTradeFile.Option_type = Option_type;
               tlbTradeFile.Sec_Name = Sec_Name;
               tlbTradeFile.BookType = BookType;
               tlbTradeFile.BookTypeName = BookTypeName;
               tlbTradeFile.TerminalId = TerminalId;
               tlbTradeFile.Branch_Id = Branch_Id;
               tlbTradeFile.Buy_Sell = Buy_Sell;
               tlbTradeFile.Trade_Qty = Trade_Qty;
               tlbTradeFile.Market_Rate = Market_Rate;
               tlbTradeFile.Pro_cli = Pro_cli;
               tlbTradeFile.Party_Code = Party_Code + "_A";
               tlbTradeFile.ParticipantCode = ParticipantCode;
               tlbTradeFile.O_C_Flag = O_C_Flag;
               tlbTradeFile.Sauda_Date = Sauda_Date;
               tlbTradeFile.TradeModified = TradeModified;
               tlbTradeFile.OrderNo = OrderNo;
               tlbTradeFile.Opp_Broker_Id = Opp_Broker_Id;
               tlbTradeFile.OrderTime = OrderTime;
               tlbTradeFile.UnknowkNum = UnknowkNum;

 var remove = from aremove in db.tradeFiles
              where aremove.ID==int.Parse(gvTradeFile.SelectedRows[0].Cells[0].Value.ToString())
              select aremove;
 if(remove!=null)
    db.tradeFiles.DeleteAllOnSubmit(remove);

What can be problem? Am I using wrong query? Or any thing still remained from me?

Upvotes: 0

Views: 109

Answers (1)

Habib
Habib

Reputation: 223237

You are not calling SubmitChanges anywhere in your code you need to do:

db.SubmitChanges(); //if its LINQ to SQL

Upvotes: 2

Related Questions