我在用:
string selectString =
"SELECT username, password " +
"FROM users " +
"WHERE username = '" + user + "' AND password = '" + password + "'";
MySqlCommand mySqlCommand = new MySqlCommand(selectString, Program.mySqlConnection);
Program.mySqlConnection.Open();
String strResult = String.Empty;
strResult = (String)mySqlCommand.ExecuteScalar();
Program.mySqlConnection.Close();
if (strResult.Length == 0)
{
responseString = "invalid";
InvalidLogin = true;
} else {
InvalidLogin = false;
}
在 strResult.Length 处,由于某种原因,我得到了 NullReferenceException。