標籤:vb.net html
之前登陸學校的教務系統或者考試系統,進入介面都會有“歡迎***登陸本系統”,當時就覺得挺進階。現在輪
到自己做這個例子,突然感覺是so easy!
只需簡單幾步,就可可以搞定。
(1)驗證登陸
編寫伺服器代碼如下:
protected void Page_Load(object sender, EventArgs e) { string userName = Request.Form["userName"].ToString(); //擷取使用者名稱 string userPwd = Request.Form.Get("userPwd").ToString(); //擷取密碼 SqlConnection con = new SqlConnection("server=.;database=login;uid=sa;pwd=***"); //串連資料庫 con.Open(); SqlCommand cmd = new SqlCommand("select count(*) from login where userName='"+userName+"' and userPwd='"+userPwd+"'" ,con); int count = Convert.ToInt32(cmd.ExecuteScalar()); if (count>0) { Response.Redirect("main.aspx"); //驗證成功 } else { Response.Redirect("loginFail.html"); //驗證失敗 } }
(2)同步處理的使用者名
Response.Redirect("main.aspx?userName="+userName); //隱含的是get提交 .傳入使用者名稱
//擷取使用者名稱:顯示歡迎登陸string userName = Request.QueryString["userName"].ToString(); //get提交擷取資料的方法Response.Write("<font size=24 color=red> 歡迎 " + userName + "光臨本網站</font>"); //登陸後同步處理的使用者名
(3)效果
點睛 學習最重要的是興趣,有時候突然很簡單的實現了自己以前認為很難的事情,學習的興趣,效率就會成幾十倍,幾百倍的增加。小小的例子,不僅鞏固了我們所學的知識,而且對提高我們的學校興趣和效率很有協助。
Web登陸執行個體-—同步處理的使用者名