2014-05-09 37 views
0

我在更新sqlite中的db.update的where子句中的多個列的表時遇到問題。where子句中的多列給出語法錯誤

下面是我已經嘗試過,但不接受並顯示語法錯誤。

db.getWritableDatabase().update(tablename, update((buy+dupbuy)), (column2+"=? and"+ column3+"=?"),(new String[] {getdate}+" and"+new String[] {stockname})); 

在上述查詢

  1. 第一個參數是表名進行更新。
  2. 第二個參數是要更新的值,它將指向另一個類更新方法,其中我寫了更新表的內容值
  3. 主要的三分之一部分是我需要在where子句中傳遞的參數。

但給人語法錯誤

The method update(String, ContentValues, String, String[]) in the type SQLiteDatabase is not applicable for the arguments (String, ContentValues, String, String)

請幫我在where子句中定義多個列。

謝謝你的時間。

回答

1

嘗試改變

db.getWritableDatabase().update(tablename, update((buy+dupbuy)), (column2+"=? and"+ column3+"=?"),(new String[] {getdate}+" and"+new String[] {stockname})); 

db.getWritableDatabase().update(tablename, update((buy+dupbuy)), (column2+"=? and "+ column3+"=?"),(new String[] {getdate,stockname})); 

WHERE子句中的"and"後面添加空格,並且您需要在whereArgs參數中傳遞String[]而不是String。目前您通過String

+0

非常好......非常感謝你解決了這個問題。 – Siva

1

更改拉伸代碼:

db.getWritableDatabase().update(tablename, update((buy+dupbuy)), (column2+"=? and"+ column3+"=?"),(new String[] {getdate}+" and"+new String[] {stockname})); 

db.getWritableDatabase().update(tablename, update(buy+dupbuy), column2 + " = ? and " + column3 + " = ?", new String[]{ getdate, stockname }); 
+0

感謝您的答覆..它不允許我運行,所以我認爲放置日誌也是沒有用的。但嘗試您的suggesstion將盡快更新。 – Siva

+0

直到相同的問題...錯誤:SQLiteDatabase類型中的方法update(String,ContentValues,String,String [])不適用於參數(String,ContentValues,String,String) – Siva

+0

我將編輯我的回答,看看。 –