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

            }

  • 相关阅读:
    .NET中操作SQLite
    Visual Studio 快捷键
    ADO.NET入门教程(三) 连接字符串,你小觑了吗?
    ADO.NET入门教程(二)了解.NET数据提供程序
    Xaml语法概述及属性介绍
    Csharp日常笔记
    C#基础
    PAT-L3-球队“食物链”-dfs-状压-set
    TOJ1302: 简单计算器 && TOJ 4873: 表达式求值&&TOJ3231: 表达式求值
    TOJ 3973 Maze Again && TOJ 3128 简单版贪吃蛇
  • 原文地址:https://www.cnblogs.com/ahuang1118/p/172519.html
Copyright © 2011-2022 走看看