1
IM試圖從表中的數據,然後將其添加到另一個表。我需要KEY_CATEGORYID
從表1自動增量,然後我需要將其添加到表2和4.我不能 找出如何做到這一點KEY_CATEGORYID
將只有一個值後createBudget
方法已完成,發生在addId
後完成這個我完全難住什麼做任何幫助,非常感謝。獲取和將數據添加到現有的SQLite數據庫
public SQLiteDatabase createBudget(String bname, String bpay, String bamount,
String bmemo) {
// TODO Auto-generated method stub
ContentValues t1 = new ContentValues();
ContentValues t2 = new ContentValues();
ContentValues t4 = new ContentValues();
t1.put(KEY_NAME, bname);
t1.put(KEY_PAYDAY,bpay);
t2.put(KEY_AMOUNT, bamount);
t2.put(KEY_DATE, date);
t4.put(KEY_MEMO, bmemo);
t4.put(KEY_DATE,date);
ourDatabase.insert(DATABASE_TABLE1, null, t1);
ourDatabase.insert(DATABASE_TABLE2, null, t2);
ourDatabase.insert(DATABASE_TABLE4, null, t4);
addID(bname);
return ourDatabase;
}
private void addID(String bname) throws SQLException {
// TODO Auto-generated method stub
ContentValues num = new ContentValues();
List<String> nums = new ArrayList<String>();
int number = 0;
String[] columns = new String[]{KEY_CATEGORYID};
Cursor c = ourDatabase.query(DATABASE_TABLE1, columns,KEY_CATEGORYID + "=?", new String[] {String.valueOf(bname)}, null, null, null, null);
if(c!= null)
{
if (c.moveToFirst()) {
nums.add(c.getString(0));
number = nums.get(0);
}
num.put(KEY_CATEGORYID, number);
}
ourDatabase.insert(DATABASE_TABLE2, null, num);
ourDatabase.insert(DATABASE_TABLE4, null, num);
}
http://stackoverflow.com/questions/9109438/how-to-use-an-existing-database-with-an- Android的應用程序/ 9109728#9109728 –
@YaqubAhmad感謝你的幫助 – newProgrammer