For example, when creating a command text for a SqlServer ce statement, the example has you use
command.CommandText = "INSERT INTO Region (RegionID, RegionDescription) VALUES (@id, @desc)";
I understand how to run sql queries, but have always just passed the database system a string with sql statements. This is new to me, and I would like to understand. Does the @ mean that it is a variable, so when it parses the string, it will insert the value of the variable id into the string where it says @id?
I know in php, double quotes allow the parser to parse a variable value within a string, and am wondering if this is similar.
However, to test it, I made a simple program to test this theory.
string id = "FOO";
MessageBox.Show("@id");
It showed the literal @id, so this has left me confused. Thanks ahead for any help!
I just feel the need to understand what I am typing, not just mindlessly following the examples.
In this case
@defines the variable that you want to pass into your SQL statement.For instance:
And then you add it to your command like that:
Then, in your
select@idand@descwill use values passed as a value of SqlParameter.Therefore, if you just output
"@id"it will be interpreted as a normal string. It only makes sense while used inside a SQL query.