Home > Net >  Judge if the condition is true, what reason did not perform if block of code
Judge if the condition is true, what reason did not perform if block of code

Time:09-30

Try
{
Conn. The Open ();
SqlCommand comm=conn. CreateCommand ();
Comm.Com mandText="select * from Admin where UserName='" + User +"' ";
SqlDataReader reader=comm. ExecuteReader ();
If (reader. The Read ())
{
String password=reader. Get string (reader. GetOrdinal (" password "));
String username=reader. Get string (reader. GetOrdinal (" username "));
String useritem=reader. Get string (reader. GetOrdinal (" UserType "));//user level
//MessageBox. Show (useritem);
MessageBox. Show (password);
MessageBox. Show (username);
If (password==Pwd)
{
If (useritem. Equals (uiterm))
MessageBox. Show (" welcome "+ username);
New Thread (()=& gt; Application. The Run (new Menu ())). The Start ();
Enclosing the Close ();
}
The else
{
MessageBox. Show (" password error!" );
The UserName. Text="";
PassWord. The Text="";
}
}

CodePudding user response:

Which if judgment is true, which didn't perform a code block

CodePudding user response:

Judging the password and the Pwd that, two equal, the condition is true, but it is below the statement in the else block

CodePudding user response:

The two are not equal, you carefully check it

CodePudding user response:

If there's more Spaces or point in the string

CodePudding user response:

Is the same ah, I put the two respectively displayed are the same

CodePudding user response:

No, it is a simple string

CodePudding user response:

Add in monitoring three values
What are the password, see
The Pwd, see what the result is
Password==Pwd of whether that is true or false

CodePudding user response:

reference 5 floor qq_37214716 reply:
is the same ah, I put the two separate display are the same.
see screenshots

CodePudding user response:

If (useritem. Equals (uiterm))

CodePudding user response:

Have you step?? As long as it is equal if judge must perform if inside, or we don't want to wait (to judge the if don't want to, etc.)

CodePudding user response:

Copy the password==Pwd to instant window, look at the results

CodePudding user response:

Password==Pwd didn't see the definition of the Pwd, whether there is a space under the most good-looking, or to determine whether a length equal to the first,

CodePudding user response:

Password. Equals (PWD) not to go, you are just watching them grow as==than string and stuff

CodePudding user response:

Compare with the==is the most unreliable, and if else so long can prove that you don't equal,
Personal advice to write so you judge
 if (string.Com pare said (password, Pwd, true)==0) 


Of course, if you through a MessageBox. Show to see the result is consistent with the else but go, do not prevent comparison in the password, the Pwd followed by a. Trim (); Method,

CodePudding user response:

Your computer program began to strike, the core began to resist, be careful your computer automatically jump shoot you oh,

CodePudding user response:

The password/Pwd is what kind of? String can't do this

CodePudding user response:

If confirmed that two strings are the same, restart the computer,
If doesn't work, try the 360 first aid kit with the
Not yet, reshipment system! The computer has a problem

CodePudding user response:

1. In c # for string types,==will be the value of the string, use the==judgment is no problem,
2. May be a space before and after the string of characters, the original poster Show () it didn't find it,

CodePudding user response:

Absolutely not equal, just what do you think are equal, compare it carefully,

CodePudding user response:

refer to 17th floor wang_peng response:
if confirmed two strings are the same, restart the computer,
If doesn't work, try the 360 first aid kit with the
Not yet, reshipment system! There is something wrong with the computer the

This answer cattle B, a great god!!!



CodePudding user response:

Program is,
Equal is equal, not possible you say equal but ran into the else,
See if have a space before and after, or case caused by different, coupled with the code, then screen out look at:

MessageBox. Show ("==="+" + "===" + Pwd + "===");

CodePudding user response:

Should use STRCMP to compare strings

CodePudding user response:

 if (password. The Trim (). The Upper ()==Pwd. The Trim (). The Upper ()) 

CodePudding user response:

Application. The run (form), the code must run in the main thread,
If not in the main thread running news cycle, the process to this. The close ended, give you the illusion of the if your program is not running,

CodePudding user response:

reference 24th floor Ma Shaohua response:
application. The run (form), the code must run in the main thread,
If not in the main thread running news cycle, the process to this. The close ended, give you the illusion of the if your program is not running,

Didn't see the description of the building Lord, please ignore my answer,

CodePudding user response:

Your judgment is a MessageBox. Show (password).
MessageBox. Show (username);
If (password==Pwd)
{
Why is the username

CodePudding user response:

Reader. The Read () if a value can be Read out to true execution code in it, and then the if (password==Pwd) equal to the code is executed, you add a breakpoint on the reader. The Read () there, and see whether this has a value

CodePudding user response:

Words, which is it if you can't get into?
First problem:
String password=reader. Get string (reader. GetOrdinal (" password "));
String username=reader. Get string (reader. GetOrdinal (" username "));
String useritem=reader. Get string (reader. GetOrdinal (" UserType "));//user level
All three of the breakpoint look, then you the password==PWD also break points and see whether he is true? Because two if I don't know what you said into not to go

CodePudding user response:

The original poster to step through to that if, in the monitor inside out the value of the two strings and then compare the manually, send screenshots to look.

CodePudding user response:

The stick good buzznullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  •  Tags:  
  • C #
  • Related