kobi55
kobi55

Reputation: 103

Dapper c# mssql select with parameters return null

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 :)?

Upvotes: 0

Views: 297

Answers (1)

Matt Evans
Matt Evans

Reputation: 7575

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

Upvotes: 3

Related Questions