Thread: OleDB connection

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #4
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,130
    That's a lot of overhead to get confused. Try to keep your programs simpler while learning new things.

    Code:
    using System;
    using System.Data.OleDb;
    
    namespace ConsoleApplication1
    {
      internal class Program
      {
        public static bool ValidateUser(string password, string username)
        {
          const string connectionString = "Provider=MSDAORA;Data Source=xe;Persist Security Info=True;User ID=GOL;Password=kaRkaRr0t";
          const string sql = "SELECT COUNT(*) FROM USERLOGIN WHERE USERNAME = @name AND PASSWORD = @password";
    
          using (var connection = new OleDbConnection(connectionString))
          {
            using (var command = new OleDbCommand(sql, connection))
            {
              command.Parameters.AddWithValue("@name", username);
              command.Parameters.AddWithValue("@password", password);
    
              return Convert.ToInt32(command.ExecuteScalar()) > 0;
            }
          }
        }
    
        public static void Main(string[] args)
        {
          const string user = "test";
          const string password = "secret";
    
          bool isValid = ValidateUser(password, user);
    
          Console.WriteLine("{0}/{1} is {2}", user, password, isValid ? "valid" : "invalid");
        }
      }
    }
    I couldn't test it here, but it should demostrate what steps you have to take to authenticate somebody.
    Last edited by nvoigt; 12-01-2012 at 11:46 AM. Reason: replaced ExecuteReader with ExecuteScalar
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Ftp Connection with C?
    By ulaas in forum C Programming
    Replies: 9
    Last Post: 12-03-2009, 10:56 AM
  2. Using OleDb in C#?
    By jcafaro10 in forum C# Programming
    Replies: 10
    Last Post: 06-29-2009, 10:28 AM
  3. OLEDB Provider Properties
    By IfYouSaySo in forum Windows Programming
    Replies: 0
    Last Post: 04-26-2006, 12:26 AM
  4. Writing OLEDB Provider
    By IfYouSaySo in forum Windows Programming
    Replies: 0
    Last Post: 04-06-2006, 04:55 PM
  5. OLEDB Connection String to Excel
    By gozlan in forum C# Programming
    Replies: 4
    Last Post: 07-06-2003, 01:42 PM