I am developing a simple app that inserts in database and searches in the inserted data
i created the database and i could see all the rows inserted...i want to search for the rows using the Name column
i am having an error and i don't know where is the error line
below is my code to create the database.
sampleDB = this.openOrCreateDatabase(SAMPLE_DB_NAME, MODE_PRIVATE, null);
sampleDB.execSQL("CREATE TABLE IF NOT EXISTS "+SAMPLE_TABLE_NAME +
" (Id INT(50), Name VARCHAR," +
" Price INT(50), Qty INT(50), Discount INT(50), Category INT(10));");
and here's the code to search in the database
Button saveButton = (Button) findViewById(R.id.search_button);
saveButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
String searchStr = search.getText().toString();
Cursor c = sampleDB.rawQuery("SELECT Name, Price FROM "+SAMPLE_TABLE_NAME+" WHERE Name like '"+searchStr+"'", null);
if (c != null ) {
if (c.moveToFirst()) {
do {
String name = c.getString(c.getColumnIndex("Name"));
int cat = c.getInt(c.getColumnIndex("Category"));
results.add("" + name + ",Age: " + cat);
Log.v("Fname", name);
Log.v("Cat", cat+"");
}while (c.moveToNext());
}
}
}
});
knowing that searchStr has the name i want to search for in the database
here's the error i am having
Bad request for field slot 0,-1. numRows = 18, numColumns = 2
FATAL EXCEPTION: main
java.lang.IllegalStateException: get field slot from row 0 col -1 failed
any help please ?