1

is there any probleme with this sql syntax

  @{
var userId = Request["UserId"];
     var db = Database.Open("intranet");
    var query3 = "INSERT INTO CongeAccept(UserId,DateDebut,DateFin,TypeConge) SELECT UserId,DateDebutDemande,DateFinDemande,TypeConge FROM DemandeConge WHERE UserId = '" + userId + "'";
            db.Execute(query3); }

1 Answer 1

1

is there any probleme with this sql syntax

It largely depends on where the userID is coming from. If its user supplied you're opening yourself up to a SQL injection attack

You should use parameters instead. As added bonus you don't have to worry about putting quotes around the values.

 var query3 = @"INSERT INTO CongeAccept(UserId,DateDebut,DateFin,TypeConge) 
               SELECT UserId,DateDebutDemande,DateFinDemande,TypeConge 
               FROM DemandeConge 
               WHERE UserId = @0";
 db.Execute(query3, userId ); 
Sign up to request clarification or add additional context in comments.

9 Comments

tnks fr the notice dudde ^^ so when i want to use a variable name i put "@" before the var name ?
Yeah but the variable name doesn't actually matter since it replaces by the order it appears. See the Database.Execute Method
unfortunately :s :s it shows me this msg : A parameter is missing. imageup.fr/uploads/1330386509.png
it should be db.Execute(query3, UserId ) not db.Execute(query3)
i already use it but it doesn't work they show me this msg : imageup.fr/uploads/1330386739.png
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.