I am aware of the existence of this question: Procedure error " Must declare the scalar variable "
But it does not solve my problem. My situation is as follows:
I have a common sql query:
select id from USUARIOS where login = @txtlogin and password = @txtpassword
This is my object SqlCommand
:
conn = new SqlConnection(ConnectionString);
conn.Open();
var com = new SqlCommand(command, conn);
I create SqlCommand
, the connection opens normally, and I add the parameters like this:
SqlParameter param = new SqlParameter();
param.ParameterName = "@txtlogin";
param.Value = "teste";
//command é o meu SqlCommand devidamente inicializado
command.Parameters.Add(param);
param = new SqlParameter();
param.ParameterName = "@txtsenha";
param.Value = "teste";
//command é o meu SqlCommand devidamente inicializado
command.Parameters.Add(param);
However, when I run the query, it gives me the error:
Must declare the scalar variable @txtlogin
What can I be doing wrong?