0

in my case Dapper return null when i try use parameters:

User user;
            using (var c = new SqlConnection(con.GetConnectionString()))
            {

                var sql = @$"SELECT 
                                tt_id as Id,
                                tt_imie AS Name, 
                                tt_nazwisko AS Surname, 
                                tt_login AS Login
                            FROM nteren_terenowi
                            WHERE tt_login = '@Login'
                                  AND tt_pin = @Pin
                                  AND tt_czy_aktywny = 1;";

                user = c.QueryFirstOrDefault<User>(sql, credentials.GetParam(), commandTimeout: 3000); //its null
            }

    public class UserIdentityMobile : IDynamicParameters
    {
        public string Login { get; set; }
        public string Pin { get; set; }

        public DynamicParameters GetParam()
        {
            Dictionary<string, object> dictionary = new Dictionary<string, object>();
            dictionary.Add("Login", this.Login);
            dictionary.Add("Pin", this.Pin);

            return new DynamicParameters(dictionary);
        }
    }

if I pass params hardcoded in sql user is not null. Someone can help me :)?

1
  • 1
    Adding single quotes around a parameter placeholder transform that placeholder in a literal string. It is no more used to signal where the parameter value should be used by the dbengine but it is taken at its literal value. Remove the single quotes around @Login Commented May 26, 2020 at 14:20

1 Answer 1

3

I think WHERE tt_login = '@Login' should be WHERE tt_login = @Login

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.