Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • romin 4 posts 95 karma points
    Oct 18, 2017 @ 09:56
    romin
    0

    Sql query email escape '@'

    Hello folks,

    This is my first post in umbraco forum. i am stuck with a problem for sometime and can't see a solution...hope someone here can help me.

    var email = "[email protected]"; var sqlquery = "Delete From Table Where email = '" + email + "'"; db.Execute(sqlquery);

    this statement fails with "@" sign in email address. how can i escape this character and make the query succeed?

    The error message: Parameter '@' specified but none of the passed arguments have a property with this name

    Thanks in advance.

  • Nik 1625 posts 7295 karma points MVP 7x c-trib
    Oct 18, 2017 @ 10:07
    Nik
    0

    Hi Romin,

    Your question raises a few questions and quite a big concern.

    It looks like you are constructing an SQL query, but you are exposing yourself to SQL injection (assuming that at some point the email is going to be populated dynamically).

    Where are you writing this code? I'm guessing in a template file?

    Thanks,

    Nik

  • romin 4 posts 95 karma points
    Oct 18, 2017 @ 11:25
    romin
    0

    @Nik Thanks for the reply. I am writing this query in a surface controller.

  • romin 4 posts 95 karma points
    Oct 18, 2017 @ 11:44
    romin
    101

    I found the solution in case someone else face the same issue.

    var sql_query = new Sql("DELETE FROM Table").Where("UserName=@0", email).Where("Id=@0", id);

Please Sign in or register to post replies

Write your reply to:

Draft