jpavlov
jpavlov

Reputation: 2261

Adding SqlParameter

I am re-writing a login process I wrote in Console to a web based application and keep getting hung up when I add the SqlParamater. For some reason it doesn't recogize FirstName and gives the error "The FirstName does not exist in current context".

How can I solve this?

//set the command object so it knows to execute a stored procedure
cmd.CommandType = CommandType.StoredProcedure;

//Doesn't understand line under....
cmd.Parameters.Add(new SqlParameter("@FirstName", FirstName)); 
parmReturnValue = cmd.Parameters.AddWithValue("@UserId", SqlDbType.Int);
parmReturnValue.Direction = ParameterDirection.ReturnValue;

Upvotes: 0

Views: 309

Answers (2)

Oded
Oded

Reputation: 499302

The variable FirstName that you are passing to the SqlParameter constructor is not recognized - where is it defined?

You need to ensure that this variable is accessible in the scope of the code you posted.

Contrary to the answer by @gov, this has nothing to do with SQL, since you are getting this as a compilation error.

Upvotes: 1

kobe
kobe

Reputation: 15835

Please check in the database what name you gave in the stored procedure

@FirstName"

the above should match the argument in stored procedure

Upvotes: 1

Related Questions