⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 usersdb.cs

📁 东软内部材料(四)asp等相关的教学案例 
💻 CS
字号:
using System;
using System.Data;
using System.Data.SqlClient;
using System.Collections;

namespace IBuyAdventure
{
   public class UsersDB
   {

   private string m_ConnectionString;

   public UsersDB( string dsn ) {
      m_ConnectionString = dsn; 
   }

   public void AddNewUser(string customerName, string password) {

          String insertStatement = "INSERT INTO Accounts (CustomerName, Password) values ('" + customerName + "', '" + password + "')";

          SqlConnection sqlConnection = new SqlConnection(m_ConnectionString);
          SqlCommand myCommand = new SqlCommand(insertStatement, sqlConnection);

          myCommand.Connection.Open();
          myCommand.ExecuteNonQuery();
          myCommand.Connection.Close();
      }      
  
  public bool UserExists(string customerName){
          SqlConnection sqlConnection = new SqlConnection(m_ConnectionString);
          SqlDataAdapter sqlAdapter1 = new SqlDataAdapter("SELECT CustomerName FROM Accounts WHERE CustomerName='"+customerName+"'", sqlConnection);

          DataSet accountDetails = new DataSet();
          sqlAdapter1.Fill(accountDetails, "accountDetails");

          if (accountDetails.Tables[0].Rows.Count < 1) {
            return false;
          }
		  else
		  	return true;
          
}
      
      public bool ValidateLogin(String customerName, String password) {
      
          SqlConnection sqlConnection = new SqlConnection(m_ConnectionString);
          SqlDataAdapter sqlAdapter1 = new SqlDataAdapter("SELECT * FROM Accounts WHERE CustomerName='"+customerName+"'", sqlConnection);

          DataSet accountDetails = new DataSet();
          sqlAdapter1.Fill(accountDetails, "accountDetails");

          if (accountDetails.Tables[0].Rows.Count < 1) {
            return false;
          }
          
          return (String.Compare(password.Trim(), ((String) accountDetails.Tables[0].Rows[0]["Password"]).Trim()) == 0);
      }
   }

}


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -