4

ユーザーが特定の日付の名前やその他の詳細を入力するアプリケーションがあります。ユーザーが追加しようとしている値/名前がデータベース列nameに既に存在するかどうかを確認する必要があります。私はこのコードを持っていますが、1 つの値しか選択しないため、これは機能しません。ありがとう

Cursor c = dbe.rawQuery("SELECT name FROM tbl_user WHERE meeting_date LIKE'" + mydate + "'", null);

if ((c.getString(3)).equals(editTextName.getText().toString()))

{
// do something
}
4

2 に答える 2

3

フィールド内の値の存在のみをチェックする場合、最も簡単な方法は、適切なフィルターを使用して選択カウントを行うことです。

の線に沿った何か

SELECT count(*)
FROM tbl_user
WHERE meeting_date LIKE ' + my_date'
AND name = ' + editTextName.getText() + '

これにより、これらの値がテーブルに存在するかどうかを簡単かつ迅速に判断できます。

複数のテーブルをチェックする必要がある場合は、それらのテーブル間で結合を行い、それに応じてフィルターを作成する必要があります。

たまたま SQL をよく理解していない場合。
このサイトは出発点として適しています: W3Schools SQL チュートリアル

お役に立てれば。

于 2012-04-29T17:50:45.080 に答える
1

You are only selecting one column (name) and yet in your if you are trying to compare the contents of a (non-existent) third column (Not sure why you're trying to do that, but it's a problem, obviously).

Rather than trying to do it that way, why not use the column title?

So your if would look like this (and it doesn't matter what position the column is in your cursor):

if (c.getString(c.getColumnIndex("name")).equals(editTextName.getText().toString()))
于 2012-04-29T18:05:16.667 に答える