Anonymous
Как проверить, существует ли запись?
Сообщение
Anonymous » 19 фев 2026, 05:47
Я хочу проверить, существует ли запись.
MainActivity.class:
Код: Выделить всё
public void onTextChanged(CharSequence s, int start, int before, int count) {
System.out.println("Ontext changed " + new String(s.toString()));
strDocumentFrom = s.toString();
if(s.toString().isEmpty()){
} else {
try{
strTransactionDate = dbHelper.getTransactionDateByDocumentNumber(strDocumentFrom);
//strTotalAmount = dbHelper.getTotalAmountByDocumentNumber(strDocumentFrom);
//strVan = dbHelper.getVanByDocumentNumber(strDocumentFrom);
//etTransactionDate.setText(strTransactionDate);
//etTotalAmount.setText(strTotalAmount);
//Log.d("Van", "" + strVan);
//etVan.setText(strVan);
} catch (SQLiteException e) {
e.printStackTrace();
Toast.makeText(ReceivingStocksHeader.this,
"Document number does not exist.", Toast.LENGTH_SHORT).show();
}
}
DBHelper.class:
Код: Выделить всё
// TODO DISPLAYING RECORDS TO TRANSRCVHEADER
public String getTransactionDateByDocumentNumber(String strDocumentNumber){
String[] columns = new String[]{KEY_TRANSACTIONDATE};
Cursor c = myDataBase.query(TBL_INTRANS,
columns, null,
null, null, null, null, null);
if(c != null){
c.moveToFirst();
String date = c.getString(0);
return date;
} else {
Log.d("Error", "No record exists");
}
return null;
}
Он не доходит до блока catch для отображения всплывающего уведомления. Что я делаю не так?
Подробнее здесь:
https://stackoverflow.com/questions/204 ... ord-exists
1771469264
Anonymous
Я хочу проверить, существует ли запись. MainActivity.class: [code]public void onTextChanged(CharSequence s, int start, int before, int count) { System.out.println("Ontext changed " + new String(s.toString())); strDocumentFrom = s.toString(); if(s.toString().isEmpty()){ } else { try{ strTransactionDate = dbHelper.getTransactionDateByDocumentNumber(strDocumentFrom); //strTotalAmount = dbHelper.getTotalAmountByDocumentNumber(strDocumentFrom); //strVan = dbHelper.getVanByDocumentNumber(strDocumentFrom); //etTransactionDate.setText(strTransactionDate); //etTotalAmount.setText(strTotalAmount); //Log.d("Van", "" + strVan); //etVan.setText(strVan); } catch (SQLiteException e) { e.printStackTrace(); Toast.makeText(ReceivingStocksHeader.this, "Document number does not exist.", Toast.LENGTH_SHORT).show(); } } [/code] DBHelper.class: [code] // TODO DISPLAYING RECORDS TO TRANSRCVHEADER public String getTransactionDateByDocumentNumber(String strDocumentNumber){ String[] columns = new String[]{KEY_TRANSACTIONDATE}; Cursor c = myDataBase.query(TBL_INTRANS, columns, null, null, null, null, null, null); if(c != null){ c.moveToFirst(); String date = c.getString(0); return date; } else { Log.d("Error", "No record exists"); } return null; } [/code] Он не доходит до блока catch для отображения всплывающего уведомления. Что я делаю не так? Подробнее здесь: [url]https://stackoverflow.com/questions/20415309/how-do-i-check-if-a-record-exists[/url]