我正在使用linq从数据库中删除数据。我用Google搜索,并进行查询。我正在使用以下查询。
当我把调试器放在这上面时,它没有显示任何错误。它很好。但是当我检查我的数据库时,记录不会被删除。
同时进行插入操作:
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);
有什么问题?我使用错误的查询吗?或者还有什么东西还留在我身边?
答案 0 :(得分:2)
您不需要在代码中的任何位置调用SubmitChanges
:
db.SubmitChanges(); //if its LINQ to SQL