2011-08-19 54 views
0

我寫了一個條件,如果檢查字符串FKLoadStatus是否是「C」。但它不工作,即使當字符串FKLoadStatus返回值「C」本身......任何人都會檢查是否有任何在代碼中的錯誤...... 我從sqllite數據庫如果條件不起作用

sql=" SELECT trim(FKLoadStatus) as FKLoadStatus , tblLoad.PKLoad, " + 
        "date(tblLoad.PlannedLoadDate) AS PlannedLoadDate, tblLoad.Carrier," + 
        " tblLoad.FKCarrierDriver, COUNT(tblDelivery.FKLoad) AS NoOfDeliveries ," + 
        " DriverReportTime FROM tblLoad LEFT OUTER JOIN tblDelivery" + 
        " ON tblLoad.PKLoad = tblDelivery.FKLoad WHERE PKLoad = ? " + 
        " GROUP BY FKLoadStatus , tblLoad.PKLoad, tblLoad.PlannedLoadDate, " + 
        " tblLoad.Carrier, tblLoad.FKCarrierDriver , DriverReportTime"; 

      dbAdapter = new DatabaseAdapter(this); 
      dbAdapter.open(); 

      cursor=dbAdapter.ExecuteRawQuery(sql,strpkManifest);   

      if (cursor.moveToFirst()) 
      ManifestNo.setText(cursor.getString(cursor 
         .getColumnIndex("PKLoad"))); 
      ManifestDate.setText(cursor.getString(cursor 
        .getColumnIndex("PlannedLoadDate"))); 
      Carrier.setText(cursor.getString(cursor.getColumnIndex("Carrier"))); 
      CarrierDriver.setText(cursor.getString(cursor.getColumnIndex("FKCarrierDriver"))); 
      DepotReportTime.setText(cursor.getString(cursor.getColumnIndex("DriverReportTime"))); 
      NoofDeliveries.setText(cursor.getString(cursor.getColumnIndex("NoOfDeliveries"))); 
      FKLoadStatus=cursor.getString(cursor.getColumnIndex("FKLoadStatus")); 


      if FKLoadStatus!="C") 
      { 
       confirm_Depot_button.setEnabled(true); 

      } 
      else 
      { 
       confirm_Depot_button.setEnabled(false); 


} 

回答

7

你需要比較使用.equals()方法,而不是對象引用的直接比較字符串ascessing FKLoadStatus的價值。

+0

感謝您的回答 –

1

如果你比較字符串,你應該使用.equals()方法:

if (!"C".equals(FkLoadStatus)) { 
    confirm_Depot_button.setEnabled(true);  
} 
else { 
    confirm_Depot_button.setEnabled(false); 
} 

甚至更​​好,你可能只是:

confirm_Depot_button.setEnabled(!"C".equals(FkLoadStatus)); 
+0

感謝您的回答 –