登入判斷使用者名稱和密碼是否正確的程式碼(連結和讀取資料庫)

weixin_30624825發表於2007-07-26
SqlConnection sqlcon;
        string strCon = "Data Source=(local);Database=db_11;Uid=sa;Pwd=";
        string sqlstr = "select id,mima from tb_Member111 where id='" + this.TextBox2.Text.Trim() + "' and mima='" + this.TextBox3.Text.Trim() + "'";
        sqlcon = new SqlConnection(strCon);
        SqlCommand com = new SqlCommand(sqlstr, sqlcon);
        sqlcon.Open();
        SqlDataReader read = com.ExecuteReader();
        if (read.Read())
        {
            //向目標頁面傳遞資料
            string sUrl = "BrowserGoods.aspx?id=" + TextBox2.Text;
            Response.Redirect(sUrl);
        }
        else
        {
            Response.Write("<script>alert('使用者名稱或密碼錯誤')</script>");
        }

轉載於:https://www.cnblogs.com/cnyyl/archive/2007/07/26/832735.html

相關文章