I use MySql , as. You need to update a specific string (let's say a string with id 55) . How can I update it?
2 answers
According to the issue of Google on request
And this answer from en-SO
It is necessary so:
ContentValues cv = new ContentValues(); cv.put("Field1","Bob"); //These Fields should be your String values of actual column names cv.put("Field2","19"); cv.put("Field2","Male"); myDB.update(TableName, cv, "_id="+id, null); - I pointed out Mysql - elik
- @elik, well, yes, the php script will do - YuriySPb ♦
|
Android uses LiteSQL
//Создаем экземпляр класса Базы Данных (открытую для чтения и записи) SQLiteDatabase database = myDB.getWritableDatabase(); //Создадим объект класса ДЛЯ ДОБАВЛЕНИЯ НОВЫХ СТРОК В ТАБЛИЦУ ContentValues contentValues = new ContentValues(); //Добавляем новое значение (если строка состоит из 5 колонок, то для каждой такая строка) contentValues.put(НАЗВАНИЕ КОЛОНКИ, info); //Вызываем метод update (Имя Таблицы, обновленный контент, Строка условия и массив аргументов для строки условия) database.update(TABLEMAIN_NAME, contentValues, DBHelper.MAIN_TABLE_ID + "= ?", new String[]{id}); //или та же строчка что выше, но по другому написана database.update(TABLEMAIN_NAME, contentValues, TABLE_ID " = " + id, null); - Thanks to her, I have no problems with the sql problem - elik
- It's just that there is an android tag in the question and I thought that LiteSQL, although there is not much difference, SQL is used both there and there. You can also write the last line: database.update (TABLEMAIN_NAME, contentValues, TABLE_ID "=" + id, null); - Eugene Zaychenko
- mysql is more accurate than a pancake from snolј) - elik
- In any case, my answer fits :) and is detailed, I think problems with understanding should not be. - Eugene Zaychenko
|