title: Check if the row already exist in database in android
body: <p>please help me. I'm trying to make a registration app that will save consumer's data. The user needs to enter his complete name together with the company he wants to register to. He can register many times as long as it is in different company. My problem in my code below is that the program only compare the user input on the first data he enter. for example, the user enter his name and the company is ABC, the program accept it, when the user enter again his name and the company is DEF the program still accept it, but when the user enter his name and the company DEF again the program still accept it which is wrong, when you change the company in ABC the program did not accept it. So what I see is that my code only comparing the data on the first info entered.</p>
  
  <p>here's my code:</p>
  
  <p>in my databaseAdapter</p>
  
  <pre><code>public Constructor getNameCp(String name) 
  {
      SQLiteDatabase db = this.getReadableDatabase();
      Constructor consName = new Constructor();
      try 
      { 
          Cursor c = db.query(Constants.DATABASE_TABLE_CONSUMER,null, Constants.CONSUMER_FULLNAME + "=?", new String[]{String.valueOf(name)},null, null, null);                                               
          if (c == null) 
          {                        
              return consName;                                   
          }
  
          else{    
              c.moveToFirst();               
              consName = new Constructor(Integer.parseInt(c.getString(0)),c.getString(c.getColumnIndex(Constants.CONSUMER_EMPNO)),c.getString(c.getColumnIndex(Constants.CONSUMER_FULLNAME)), c.getString(c.getColumnIndex(Constants.CONSUMER_CELLPHONENO)), c.getString(c.getColumnIndex(Constants.CONSUMER_COMPANY)));
          }                   
      }catch(Exception e){
          e.printStackTrace();
      }
      return consName; 
  }
  </code></pre>
  
  <p>in my activity</p>
  
  <pre><code>String name = databaseAdapter.getNameCp(fullName).getConsumerFullname();
  String comp = databaseAdapter.getNameCp(fullName).getCompanyname();
  
  if ((fullName.equals(name)) &amp;&amp; (companyName.equals(comp))){
      UpdateByEmployeeName(fullName);
      Toast.makeText(RegistrationActivity.this, "Account info already exist.", Toast.LENGTH_LONG).show();
  }else{
      String currentDateandTime = sdf.format(new Date());
      databaseAdapter.SaveConsumerDetails(new Constructor(Emp.toUpperCase(), Lastname, Firstname, Middlename.toUpperCase(), Cp, Email, fullName, careFriend, companyName, emailmark, currentDateandTime, consumerId, consumercompanycode));
  refresh();
  }
  </code></pre>