我正在設計一個ATM系統在C#和登錄功能我正在使用SQL服務器數據庫來比較輸入卡號和PIN到數據庫。當輸入正確的卡號和PIN碼時,一切正常,但當輸入的數值不正確時,我一直試圖弄清楚一段時間。有沒有人有任何想法,可能是什麼?即使我的大學講師也不知道!'其他'的if/else不執行時,它應該C#
//Select all fields from the table 'ATMCards' using the connection previously created and use the SqlDataReader to read the values
爲了簡化它,我剛纔把messagebox.show在其他所有我想要做的是,至少有它觸發!
SqlCommand cmd = new SqlCommand("SELECT * FROM [ATMCards] WHERE (cardNumber = @cardNumber) AND (PIN = @PIN)", cn);
cmd.Parameters.AddWithValue("@cardNumber", cboxSimCard.Text);
cmd.Parameters.AddWithValue("@PIN", txtboxPIN.Text);
cmd.Connection = cn;
SqlDataReader r = null;
r = cmd.ExecuteReader();
//While the reader is in execution:
while (r.Read())
{
//ADD IF NOT CONFISCATED DO THIS:
if (((Boolean)(r["confiscated"]) == notConfiscated))
{
string cNum = r["cardNumber"].ToString();
string pin = r["PIN"].ToString();
//Compare the results in the ATMCards table against those on the form used to log in
if (string.Equals(cNum,cboxSimCard.Text) && string.Equals(pin,txtboxPIN.Text))
{
MessageBox.Show("Card number "+cNum+" PIN "+pin);
//If the login details are correct then grant access to the menu screen by creating a new instance of it and hide the login form. Clear PIN to avoid the next user accessing the account
MessageBox.Show("Open form all is good");
txtboxPIN.Clear();
Form myNewForm = new Menu();
myNewForm.Show();
this.Hide();
break;
}
else
{
MessageBox.Show("Here");
}
你確定'r [「沒收」]!= notConfiscated'? – 2012-03-12 09:29:13
你應該(學會)在這裏使用調試器。 – 2012-03-12 09:30:01
我希望這臺ATM機是一個學習作業,而不是商業產品。例如,純文本密碼? – RvdK 2012-03-12 09:43:41