zoukankan      html  css  js  c++  java
  • 用户登录经典代码

    private void btnLogin_ServerClick(object sender, System.EventArgs e)
            
    {
                SqlConnection con;
                
    string sql;
                SqlCommand cmd;
                
    string id;

                con 
    = new SqlConnection("data source=(local)\\NetSdk;initial catalog=FriendsData;user id=sa");
                sql 
    = "SELECT UserID FROM [User] WHERE Login='{0}' and Password='{1}'";
                
                
    // Format the string with the values provided
                sql = String.Format(sql, txtLogin.Value, txtPwd.Value);
                cmd 
    = new SqlCommand(sql, con);
                con.Open();

                
    try 
                
    {
                    
    // Retrieve the UserID
                    id = (string) cmd.ExecuteScalar();
                }

                
    finally 
                
    {
                    con.Close();
                }


                
    if (id != null)
                
    {
                    
    // Set the user as authenticated and send him to the page originally requested.
                    FormsAuthentication.RedirectFromLoginPage(id, chkPersist.Checked);
                }

                
    else
                
    {
                    
    this.pnlError.Visible = true;
                    
    this.lblError.Text = "Invalid user name or password!";
                }

            }

  • 相关阅读:
    hdu4846 最大子正方形(dp)
    hdu4847 水题
    hdu4847 水题
    hdu4848 DFS 暴搜+ 强剪枝
    hdu4848 DFS 暴搜+ 强剪枝
    洛谷 P4999 烦人的数学作业(数位DP)
    洛谷 P4317 花神的数论题(数位DP || 快速幂)
    洛谷 P2657 [SCOI2009]windy数(数位DP)
    洛谷 P2602 [ZJOI2010]数字计数(数位DP)
    HDU 2089 不要62(数位DP)
  • 原文地址:https://www.cnblogs.com/ahuang1118/p/172519.html
Copyright © 2011-2022 走看看