c# - What does the @ do in a SQL statement? -


For example, when you create a command text for a SqlServer CE statement, for example you used

  

command.CommandText = "Insert in field (regional ID, area description) value (@id, @desc)";

I understand how to run SQL queries, but always have the database system passed a string with the SQL statement. This is new to me, and I want to understand. Does this mean that it is a variable, so when it parses the string, it will insert the value of variable ID into the string where it is written in the @ id? I know in php, double quote parsers are allowed to parse a variable value inside a string, and I am thinking that it is similar.
However, to test this, I have created a simple program to test this theory.

  string id = "FOO"; MessageBox.Show ("@ id");  

This literally showed the id @, so it left me confused. Thanks for any help! I just feel the need to understand what I am writing, not just following the examples.

In this case @ defines the variable Want to pass in the statement.

For example:

  SqlParameter param = new SqlParameter (); Param.ParameterName = "@id"; Param.Value = 666;  

And after that you can add it to your command:

  command. Parameter. Add (Ultimate);  

Then, passed in your select @id and in @desc Values ​​will be used SqlParameter

Therefore, if you just have the output "@ id" , then it will be interpreted as a normal string. It only makes sense when used in SQL queries.


Comments