c# - Check or nickname already exists in List<User> -


i creating asp website possibility register.

the nickname visitors choose register has unique.

everytime when user registers, select users database, , using foreach loop check or username exists:

private list<user> listexistingusers; listexistingusers = database.getusers(); foreach (user u in listexistingusers) {     if (u.nickname == txtnickname.text)     {         error = "username in use.";     } } 

but code above doesn't work properly. doesn't check items in list read database. possible have users same usernames, don't want.

what can solve problem? read linq, think wrong way of checking usernames list<> in opinion. think username-check must done in way.

can experts me? check sql-query, in c#.

instead of returning users db, pass username query/stored procedure , let backend check, , return status flag 1/0 - exists/doesn't.


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -