1
When mounting a Query using Addwithvalue. Even if right, the return is not as expected.
In the example below the return is Zero
var query = "SELECT nome,usuario,email,administrador FROM GSCUsuarios WHERE @parametroWhere = @parametroCondicao");
dataAdapter.SelectCommand.Parameters.AddWithValue("parametroWhere", parametroWhere);
dataAdapter.SelectCommand.Parameters.AddWithValue("parametroCondicao", parametroCondicao);
I decided to ask in the American stackoverflow and it was suggested to change the query to the following format
var query = string.Format("SELECT nome,usuario,email,administrador FROM GSCUsuarios WHERE {0} = @parametroCondicao", parametroWhere);
dataAdapter.SelectCommand.Parameters.AddWithValue("parametroCondicao", parametroCondicao);
What I’d like to understand is why the first Query didn’t work. Addwithvalue didn’t just change the values?
Doing another Query, using LIKE.. also didn’t work! How this Query should be mounted?
var query = string.Format("SELECT nome,usuario,email,administrador FROM GSCUsuarios WHERE {0} LIKE '@parametroCondicao%'", parametroWhere);
dataAdapter.SelectCommand.Parameters.AddWithValue("parametroCondicao", parametroCondicao);
Thank you
See that your parametroWhere is = parametroCondicated, it will depend on how you are running it
– Rod