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!";
                }

            }

  • 相关阅读:
    根据屏幕宽度适应屏幕样式
    设计模式之命令模式
    动态代理的使用以及其实现机制
    PLSQL链接不上oracle
    struts2自定义结果类型demo
    Tomcat虚拟路径
    SEQUENCE序列
    mysql导出数据库中建表语句和数据
    Tomcat6 启动时 Cannot assign requested address: JVM_Bind
    sql常用命令
  • 原文地址:https://www.cnblogs.com/ahuang1118/p/172519.html
Copyright © 2011-2022 走看看