0

I have a form on my web page that I want posting to my database in the background upon submitting the form. Here is my code:

if (Validation.IsValid()) 
{
    // Insert a new user into the database
    var db = Database.Open("StarterSite");

    // Check if user already exists
    var user = db.QuerySingle("SELECT Email FROM UserProfile WHERE LOWER(Email) = LOWER(@0)", email);
    if (user == null) {
        // Insert email into the profile table
        db.Execute("INSERT INTO UserProfile (Email) VALUES (@0)", email);
    }
}

This is sample code and I'm trying to interpret it. What's baffling me is that is says VALUES (@0). However, when the form on this page is submitted, it still manages to post the inputted email address though the value says (@0) ?

Any clarity would be greatly appreciated!

Regards,

Josh

(P.S, I'm new to ASP.NET)

1
  • By tagging sql you can simply check if the user exist or not by applying unique constraint. Have a look at the link which gives you detailed information about how to insert records into the database . onlinebuff.com/… Commented Aug 22, 2016 at 10:48

1 Answer 1

1

@0 refers to the first parameter. In your case it is the variable email as so;

db.Execute("INSERT INTO UserProfile (Email) VALUES (@0)", email);

You can insert more than one ordered parameter like this;

db.Execute("INSERT INTO UserProfile (Email, SecondParam) VALUES (@0, @1)", @0, @1);
Sign up to request clarification or add additional context in comments.

Comments

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.