Click here to Skip to main content
15,890,579 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have one windows application at the user side and a web service at the admin side which are connected in the LAN...when the user runs the windows application there is a login form and when the user logs in a web service call is made and a row (containing details of the user) is dynamically added into the table of the database present at the admin side. Now I want that only the specified no of users should be able to login i.e. if admin gives 3 users then only 3 users should be able to login and if the 4th user tries to login it should give an error message that no. of users have exceeded. I tried to do this using for loop as:
C#
for(count=0 ; count<noofusers mode="hold" />{
      //code for inserting the row dynamically into database
}


but here simultaneously 3 rows are added into the database

I want that when 1 user logins 1 row should be added, when another user logins the NOOfUsers should be incremented and 2nd row should be added and so on...finally when 4th user logins he should not be allowed to...

Can anyone please help me with this issue??
Posted
Updated 6-Apr-11 1:25am
v3
Comments
Henry Minute 6-Apr-11 7:04am    
Please take a look at the code snippet you posted, as it makes no sense (to me at least). If it has become mangled by the CP parser then please correct it. PLEASE DO NOT DELETE THE <pre> TAGS WHICH I HAVE ADDED FOR YOU.

1 solution

As Henry says, that doesn't make a lot of sense.
However, I think there is enough there to tell what your problem is:
You are using a for loop, when you want an if statement.

If you set up a for loop, it will do the same code several times: that is not what your description says.

When a user wants to log in, check the "number of users". If this exceeds or equals the maximum, then refuse the login. Otherwise, increase the number of users, and log them in.
if (count >= noofusers)
   {
   // Refuse login
   ...
   }
else
   {
   count++;
   ...
   }


Note that you will need something to cope with logout, and with "dead" users: for example if the PC gets re-booted without a log out you need to kill the user login and reduce the count somehow.
 
Share this answer
 
Comments
Ankur\m/ 6-Apr-11 7:23am    
:thumbsup:
#realJSOP 6-Apr-11 7:29am    
5 - Proposed as answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900