DataSet案例:使用者登入入門8

來源:互聯網
上載者:User

先建立一個表並輸入資料:

為這個資料庫建立一個強型別資料集,並建立幾個自訂的方法

首先是錯誤次數清零

然後是錯誤次數增加

最後是根據輸入的username來得到資料

設計一個表單,其中登入按鈕的ID是:login

雙擊這個按鈕,在產生的按鈕事件中輸入:

private void login_Click(object sender, EventArgs e)        {            T_PersonTableAdapter adapter = new T_PersonTableAdapter();            string username = txtUsername.Text;            var users = adapter.GetDataByUserName(username);            if (users.Count <= 0)            {                MessageBox.Show("沒有這個使用者");            }            else            {                //說明有這個使用者,判斷下密碼                if (txtPassword.Text == users[0].Password)                {                    MessageBox.Show("歡迎登入");                    adapter.errorTimes清零(username);                }                    //看是否是登入次數過多的                    //太多的就是惡意登入了,直接return                else if (users[0].ErrorTimes>3)                {                    MessageBox.Show("嘗試次數過多");                    return;                }                    //錯誤次數小於3次的話提示下                else                {                    MessageBox.Show("密碼錯誤");                    adapter.errorTimes增加(username);                }            }        }

這樣就完成了登入的驗證,程式清晰明了.

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.