1
Why the code below does not work (does not delete)?
using (Banco db = new Banco()) {
String strSql = "Delete from Cliente where codcliente=" + Session["_uiUserID"];
db.Cliente.SqlQuery(strSql);
db.SaveChanges();
}
You’re not throwing any Exception
and catching the string within the variable strSql
and running directly on the bank works normal.
These other methods, in this case, db.Savechanges() it executes Executenonquery?
– f.fujihara
It is necessary to give more details. What exactly is this class
Banco
. I imagine, but it may be that the problem lies precisely in being something other than what I imagine. Where does it come fromSession["_uiUserID"]
? There is the element_uiUserID
in this dictionary? What is the value of this variable at the moment? There is a row with the columncodcliente
with exactly the same value as the variable? No difference at all? TheSaveChanges()
Is that correct? I’m not even going to discuss the security flaw you have there, I’m going to consider that it’s just an example that will never run in production.– Maniero
From what I’m seeing, there are missing quotation marks('') on this _uiUserID. Your Where clause is probably empty.
– f.fujihara
@bigown has never seen such a big case of vulnerability.. Just change my cookie and I can delete all BD clients...
– dcastro
If you’re using Entity Framework ? Because, that’s unnecessary if what I asked you is affirmative !!! Use your own method for this!.
– user6026
Hey, guys, I changed the method to the way Maia posted it and it worked. This project is only of study even then ta the reason of vulnerabilities. @bigown answering your questions: Session["_uiUserID"] is the User id and was coming normally (filled), the codclient line exists in the same way and Savechanges was not working and the reason I do not know, but using Remove worked cool. Thank you for all your answers.
– Junior Dias
The questions were to/ help you find the solution.
– Maniero
I know @bigown, thanks for that ^^
– Junior Dias