Sir, I pay attention sir, you said i am passing 2parameters now i am passing 3parameters and login means it shows login successful with wrong userid password also i think my sql query should be change here
You are clearly not paying attention, neither here nor in your class.
You have repeatedly been told that you need to check the results of your query. You have been told how to do that. And yet you continue to ask how to do what you have already been told how to do, and insist that you need to change your query rather than your code.
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
How many times do I need to say it: Do not post a success message when you have not checked the result of your Database query.
This is the way you should do it:
int result = cmd.ExecuteNonQuery(); // always capture the result
if (result == 1)
MessageBox.Show("Login was successful");
MessageBox.Show("The entered details were not correct");
Also, why do you need two ids (userid and loginid)? You should only need a single id and a password.
There really is no point in continuing this thread. It does not matter how many times we tell you how to correct your code you insist on ignoring our advice. My previous reply showed you exactly how to do it correctly, and yet you just repeat the same bad code. I suggest you consider a different career path.
I have already explained more than once. When you call cmd.ExecuteNonQuery(); you must check the return value, to see whether the SQL command succeeded. Only when you have a success return can you post a message that tells the user that his action has worked. You must do this on all database access commands, never assume that your code has worked - most of the time it has not.
Yes, it shows login successful because, as I keep repeating, you post that message even when the ExecuteNonQuery fails. You need to start thinking about your code in logical steps rather than just throwing statements together and hoping it will work.
1. Perform the ExecuteNonQuery, and capture the return value.
2. Does the return value indicate success?
2.1. No - tell the user it failed.
2.2 Yes - and only at this point, tell the user it succeeded.
3. Perform other actions.
I am so glad I didn't answer this question last night.
You're not trying to think about the problem. You're not trying to read the documentation on the methods you're calling. You're not trying to read the links other people have given you to educate you on what you should be doing. You're not trying to work out what you should be doing, logically, step-by-step. You're not trying to understand anything.
What you ARE trying to do, throughout this entire thread, is get other people to write your code for you, and that will teach you nothing.