What is @ in Sqlparameter objName = new Sqlparameter ("@jobfolder", SqlDbType.Text)
views:
50answers:
4The @
is just sql server's way of identifying parameters (variables)
The SQL you are running will look something like this:
SELECT * FROM MYTABLE
WHERE MYCOLUMN = @jobfolder
In T-SQL the @
sign it perpended to variables to identify them as such.
From MSDN (Transact-SQL Variables, under Declaring a Transact-SQL Variable):
The DECLARE statement initializes a Transact-SQL variable by: - Assigning a name. The name must have a single @ as the first character. - Assigning a system-supplied or user-defined data type and a length. For numeric variables, a precision and scale are also assigned. For variables of type XML, an optional schema collection may be assigned. - Setting the value to NULL.
The variable name you pass in through your code should match the one in the stored procedure/prepared statement, hence is also needs the @
.
THank you. I also found this information online based on your answer "As you may know, ADO provides two ways to supply a stored procedure with parameter values. In the first method, you refer to the parameter name directly and simply assign a value. In the second, you build a Parameter object from scratch and add it to the Command object's Parameters collection.
Be aware, though, that when using named parameters, you must supply the @ character, which precedes every SQL Server parameter name, like so:
cmd.Parameters("@someParam") = 250
On the other hand, when you build the Parameter object from scratch, you don't need to supply the @ charcter, as seen here:
Set param = cmd.CreateParameter("someParam", adBigInt, adParamInput, 2, 250) cmd.Parameters.Append param"