philiplts188
philiplts188

Reputation: 33

Matching database with textbox.text

what i want is to match email and code between textbox and database. If it is matched , the state field will be marked "YES" <----by default empty

the following sample doesn't work anyway.. how can i make a comparing with the database values....

          OleDbConnection connection = new OleDbConnection();
        connection.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\sim\Desktop\Web.accdb";
        connection.Open();


         OleDbCommand command = new OleDbCommand();
        command.Connection = connection;

        string query = "select * from [Registration]  WHERE [Authentication] = @authentication and [Email] = @email";
        command.CommandText = query;

        command.Parameters.AddWithValue("@authentication", TextBox2.Text);
        command.Parameters.AddWithValue("@email", TextBox1.Text);
         OleDbDataReader reader = command.ExecuteReader();

         if ((reader.Read() == true))
         {
             string query1 = "UPDATE [Registration] SET [State] = 'YES'";
             command.CommandText = query1;

         }

         connection.Close();

Upvotes: 0

Views: 721

Answers (1)

Timothy Groote
Timothy Groote

Reputation: 8643

you could do this with a single query, like so :

  using(OleDbConnection connection = new OleDbConnection())
  {
    connection.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\sim\Desktop\Web.accdb";
    connection.Open();


     OleDbCommand command = new OleDbCommand();
    command.Connection = connection;

    string query = "UPDATE [Registration] SET [State] = 'YES' WHERE [Authentication] = @authentication and [Email] = @email;";

    command.Parameters.AddWithValue("@authentication", TextBox2.Text);
    command.Parameters.AddWithValue("@email", TextBox1.Text);
    command.ExecuteNonQuery();
    connection.close();
  }

Upvotes: 4

Related Questions