Hi how can i write a program to compare data entered and data stored? when we click ok. they will detect whether information store is the same.

Just an example login. but mine is asp.net i'm just using normal window application.

previously i use this is to store my password. but now i want to take the password store to compare with the one entered.

writeToB is under save();

private void writeToB()
        {
            vlAccessConnection = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + DBFileName);///

            try///
            {
                vlAccessConnection.Open();
            }
            catch (OleDbException ee)
            {
                MessageBox.Show(ee.Message + ". StackTrace: " + ee.StackTrace.ToString());
            }///

            try
            {
                //UPDATE table      SET newvalue      WHERE criteria;

                string cmdStr = "UPDATE AdminPassword SET CurrentPassword = " + password + " WHERE UserName = 'Admin'";


                OleDbDataAdapter adapter = new OleDbDataAdapter();
               

                OleDbCommand update = new OleDbCommand(cmdStr, vlAccessConnection);

                adapter.UpdateCommand = update;

                update.ExecuteNonQuery();
                vlAccessConnection.Close();
                
            }
            catch (InvalidOperationException ex)
            {
                MessageBox.Show(string.Format("Failed to insert record into Database\n{0}",ex.Message));
            }

You have to use SELECT sql statement with WHERE clause.

Erm i have tried but didn't work.
Is it something like this.? then i ned to store as variable ??

private void CompareWithDatabase()
{
            vlAccessConnection = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + DBFileName);///

            try///
            {
                vlAccessConnection.Open();
            }
            catch (OleDbException ee)
            {
                MessageBox.Show(ee.Message + ". StackTrace: " + ee.StackTrace.ToString());
            }///

            try
            {
                //SELECT column      FROM table      WHERE criteria;

                string cmdStr = "SELECT CurrentPassword AdminPassword WHERE UserName = 'Admin'";


                OleDbDataAdapter adapter = new OleDbDataAdapter();
               

                OleDbCommand select = new OleDbCommand(cmdStr, vlAccessConnection);

                adapter.Selectcommand = select;

                update.ExecuteNonQuery();
                vlAccessConnection.Close();
                
            }
            catch (InvalidOperationException ex)
            {
                MessageBox.Show(string.Format("Failed to retrieve data\n{0}",ex.Message));
            }
private void CompareWithDatabase()
{
   vlAccessConnection = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + DBFileName);

  vlAccessConnection.Open();
  string cmdStr = "SELECT CurrentPassword AdminPassword WHERE [UserName] = 'Admin'";
   OleDbCommand select = new OleDbCommand(cmdStr,   vlAccessConnection);
  object c=select.ExecuteScalar();
  vlAccessConnection.Close();

  if(c!=null){
         // Record is present
  }
 else {
     // not found
 }

I'm new at this DB stuff using C#, but based on what I've seen, you need to do something like:

OleDbConnection vlAccessConnection = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + DBFileName);

            string cmd_str = "SELECT CurrentPassword FROM AdminPassword WHERE UserName = 'Admin'";

            DataSet ds = new DataSet();

            OleDbDataAdapter da = new OleDbDataAdapter(cmd_str, vlAccessConnection);

            da.Fill(ds);

            // retrieve the CurrentPassword form the DataSet (ds)
private void CompareWithDatabase()
{
   vlAccessConnection = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + DBFileName);

  vlAccessConnection.Open();
  string cmdStr = "SELECT CurrentPassword AdminPassword WHERE [UserName] = 'Admin'";
   OleDbCommand select = new OleDbCommand(cmdStr,   vlAccessConnection);
  object c=select.ExecuteScalar();
  vlAccessConnection.Close();

  if(c!=null){
         // Record is present
  }
 else {
     // not found
 }

how do we compare?

Edited 7 Years Ago by facadie: n/a

private void CompareWithDatabase(){
      string cmdStr = "SELECT CurrentPassword 
                         AdminPassword WHERE [UserName] = ?";
   OleDbCommand select = new OleDbCommand(cmdStr,   
                                  vlAccessConnection);
   select.Parameters.Add(new OleDbParameter("?", 
             Data.OleDb.OleDbType.VarChar, 40)).Value = TextBox1.Text

    vlAccessConnection.Open();
    object c=select.ExecuteScalar();
    vlAccessConnection.Close();

    if(c!=null){
         // Record is present
    }
    else {
      // not found
   }
}
private void CompareWithDatabase()
{
   vlAccessConnection = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + DBFileName);

  vlAccessConnection.Open();
  string cmdStr = "SELECT CurrentPassword AdminPassword WHERE [UserName] = 'Admin'";
   OleDbCommand select = new OleDbCommand(cmdStr,   vlAccessConnection);
  object c=select.ExecuteScalar();
  vlAccessConnection.Close();

  if(c!=null){
         // Record is present
  }
 else {
     // not found
 }

have figure out.=) sorry to bother

This question has already been answered. Start a new discussion instead.