I have a database which is calling Medicine, there are four columns in it: id (primary key autoincrement), dId (foreign key), Name and Time. I try to add new row using insert function. This function must return id of this adding. But when I check this from debugger, I see that it returned -1.
Code:
ContentValues values = new ContentValues();
values.put("RECIPE_ID", recipeId);
values.put("MED_NAME", etMedName.getText().toString());
values.put("MED_TIME", etMedTime.getText().toString());
long mid = sqdb.insert("Medicine", null, values);
use
long mid = 0;
try
{
mid = sqdb.insertOrThrow("Medicine", null, values);
}
catch(SQLException e)
{
// Sep 12, 2013 6:50:17 AM
Log.e("Exception","SQLException"+String.valueOf(e.getMessage()));
e.printStackTrace();
}
It will tell you the probable Exception
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With