我不知道为什么while循环中的else值仍在循环,无论结果是登录名还是无效。警报对话框始终弹出。这些是我的代码。MySqlConnection conn = new MySqlConnection(); string query = "server=sample.com;port=3306;database=sample;user id=sample;password=sample";conn.ConnectionString = query;MySqlCommand cmd = new MySqlCommand("select * from wp_users", conn);try{ conn.Open(); MySqlDataReader myReader = cmd.ExecuteReader(); string user1 = ""; string pass1 = ""; //bool stopLoop = false; // stop looping for false value; while (myReader.Read()) { user1 = myReader[1].ToString(); //datacolumn -> user_login pass1 = myReader[2].ToString(); //datacolumn -> user_pass if ((user1 == txtUsername.Text) && (pass1 == txtPassword.Text)) { Intent myIntent; myIntent = new Intent(Activity, typeof(index)); string a = user1; myIntent.PutExtra("myItem", a); StartActivity(myIntent); } else { Android.Support.V7.App.AlertDialog.Builder alert = new Android.Support.V7.App.AlertDialog.Builder(Activity); alert.SetMessage("Invalid username or password"); alert.SetPositiveButton("Ok", (senderAlert, args) => { alert.Dispose(); }); alert.Show(); } } myReader.Close();}catch (MySqlException ex){ Android.Support.V7.App.AlertDialog.Builder except = new Android.Support.V7.App.AlertDialog.Builder(Activity); except.SetTitle("Please report this to our website(error server timeout)"); except.SetMessage(ex.ToString()); except.SetPositiveButton("Ok", (senderAlert, args) => { except.Dispose(); }); except.Show();}finally{ conn.Close();}
3 回答
- 3 回答
- 0 关注
- 201 浏览
添加回答
举报
0/150
提交
取消