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();
}
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".
Putting @ in front of a string tells the compuler not to process escape sequences found within the string.
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.
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.
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 :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With