Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does the @ in front of a parameter name do?

What does the @ sign does when inserted in front of parameters SQL query?

for example:

using (SqlCommand cmd = new SqlCommand("INSERT INTO [User] values (@Forename, @Surname, @Username, @Password)", con))
{
    cmd.Parameters.AddWithValue("@Forename", txtForename.Text);
    cmd.Parameters.AddWithValue("@Surname", txtSurname.Text);
    cmd.Parameters.AddWithValue("@UserName", txtUsername.Text);
    cmd.Parameters.AddWithValue("@Password", txtPassword.Text);

    cmd.ExecuteNonQuery();
}
like image 591
bandaa Avatar asked Feb 28 '13 18:02

bandaa


People also ask

What does * Do in front of a variable?

Pointers are said to "point to" the variable whose address they store. An interesting property of pointers is that they can be used to access the variable they point to directly. This is done by preceding the pointer name with the dereference operator (*). The operator itself can be read as "value pointed to by".

What is the significance of in front of a variable name?

Putting @ in front of a string tells the compuler not to process escape sequences found within the string.

What is * in front of variable in Python?

Practical Data Science using Python The asterisk (star) operator is used in Python with more than one meaning attached to it. Single asterisk as used in function declaration allows variable number of arguments passed from calling environment. Inside the function it behaves as a tuple.

What does '@' mean in C#?

In C#, a verbatim string is created using a special symbol @. @ is known as a verbatim identifier. If a string contains @ as a prefix followed by double quotes, then compiler identifies that string as a verbatim string and compile that string.


1 Answers

That's just what indicates that it is a parameter name in the query - as opposed to trying to use a field from the column.

It's not clear whether it's strictly needed when constructing the SqlParameter object, but I think it makes sense to be consistent :)

like image 107
Jon Skeet Avatar answered Nov 07 '22 04:11

Jon Skeet