public int AddNewUser(TriviaLib.User user) { int userId = 0; string query = "INSERT INTO User (Name, Password)" + " VALUES ('" + user.name + "','" + user.password + "');"; this.InsertIntoDB(query); query = "SELECT Max(UserID) FROM User;"; this.command.CommandText = query; this.connection.Open(); this.reader = this.command.ExecuteReader(); while (this.reader.Read()) { userId = Convert.ToInt32(this.reader["Max(UserID)"]); } if (this.connection.State == System.Data.ConnectionState.Open) { this.connection.Close(); } return userId; }
public bool ValidateAdmin(TriviaLib.User admin) { bool result = false; string query = "SELECT UserID FROM User WHERE Name = '" + admin.name + "' AND Password = '******';"; this.command.CommandText = query; this.connection.Open(); this.reader = this.command.ExecuteReader(); while (this.reader.Read()) { result = true; } if (this.connection.State == System.Data.ConnectionState.Open) { this.connection.Close(); } return result; }