1

I just write a simple method to get user data from database by "UserName" and its work but it's not case-sensitive , without any "toLower()" methods or something like that... and this is a big problem because it's think "Admin" equal to "admin" but this two actually not equal together ... please some body tell me what should I do???

public List<UserViewModel> GetByName(string userName)
        {
            return db.UserTBL.Where(u => u.UserName == userName).
                Select(u => new UserViewModel
                {
                    UserName = u.UserName,
                    UserFullName = u.UserFullName,
                    UserPassword = u.UserPassword,
                    UserImage = u.UserImage
                }).ToList();
        }
  • 2
    Did you check if your database collation is case-sensitive? – Rafalon Jun 24 '19 at 11:04
  • 1
    Check out [database collation guide](https://database.guide/what-is-collation-in-databases/). – Peter Wolf Jun 24 '19 at 11:05
  • I have to ask, why would you want a `case-sensitive` database ? I would do all I possible can to avoid it – GuidoG Jun 24 '19 at 11:09
  • @Rafalon thanks for your attention friend I didn't know about it and now go to find out – Reza Acolahchi Jun 24 '19 at 11:22
  • @PeterWolf thanks bro I will... – Reza Acolahchi Jun 24 '19 at 11:28
  • @GuidoG that's not a question , my question is why it's happend – Reza Acolahchi Jun 24 '19 at 11:29
  • sql-server is `case-insensitive` by default. That is why it happened. I guess you want it to stay that way, except for the password. Having usernames case-sensitive seems a bit strange to me, but if that is what you really want than Patrick Hofman's answer can help you – GuidoG Jun 24 '19 at 11:36
  • @GuidoG you right friend , I don't know about it and I just find out right now , and i'm so thankful all of you guys for learn me something new – Reza Acolahchi Jun 24 '19 at 12:16
  • [here](https://stackoverflow.com/questions/1831105/how-to-do-a-case-sensitive-search-in-where-clause-im-using-sql-server) is another option – GuidoG Jun 24 '19 at 12:39

2 Answers2

1

This is probably caused by your database being set up to match case-insensitive.

Check the collation settings of the database platform you are using. You can set it either globally, for the entire database, or for that column specifically.

Patrick Hofman
  • 153,850
  • 22
  • 249
  • 325
0

with guide guys give me here I do like picture below and it's work for me step 1 : choose the field in design mode step 2 : choose collation properties step 3 : choose windows collation step 4 : choose Dictionary sort step 5 : choose Case Sensitive and it's work for me
the five Steps I do