1
I am aware of the existence of this question: Error in previous "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 the SqlCommand
, the connection is opened 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 executing the query, it gives me the error:
Must declare the scalar variable @txtlogin
What I might be doing wrong?
Do a [mcve], missing important snippets becomes difficult to answer.
– Maniero