Update database

by pramod.deore » Thu, 02 Dec 2010 19:24:33 GMT


Sponsored Links
 Hi, I have a table with 5 columns.
1. RoomID
2. RoomName
3.RoomSuffix
4. SwitchID
5. SwitchName

I have some data in this table. Now I want to update database. How to
do this? I search for this but didn't get well answer

I had tried it like:

sampleDB =  this.openOrCreateDatabase(SAMPLE_DBNAME, MODE_PRIVATE,
null);

                        ContentValues args = new ContentValues();
                        args.put(SwitchName, switchRename);

Here I want to put SwitchName value as switchRename.
Now I execute method as:

sampleDB.update(SWITCH_TABLE_NAME, args, SwitchName
+'menuItemName',null);

But here second last argument (i.e where clause give me an error).In
where clause I want as "SwitchName = 'xyz' "  i.e where SwitchName is
xyz. How to write this where condition correctly?

-- 



Re: Update database

by Kumar Bibek » Thu, 02 Dec 2010 19:28:06 GMT


 What is the error??

Kumar Bibek
 http://techdroid.kbeanie.com 
 http://www.kbeanie.com 







-- 


Sponsored Links


Re: Update database

by Kostya Vasilyev » Thu, 02 Dec 2010 19:35:22 GMT


 The next-to-last argument to db.update is the WHERE clause, but without 
the WHERE (look it up in a SQL reference).


So while in SQL you'd write "WHERE SwitchName = value", with db.update 
you need to use "SwitchName = value".


The last argument is used supply variable values to the conditions. This 
is more efficient as well as safer. Each value in the last argument 
(which is an array) replaces one "?" placeholder in the condition.


The entire statement might look like this:

sampleDB.update(SWITCH_TABLE_NAME, args, "SwitchName = ?", new String[] 
{ oldSwitchName} );


-- Kostya

02.12.2010 14:24, pramod.deore :
Hi, I have a table with 5 columns. 1. RoomID 2. RoomName 3.RoomSuffix 4. SwitchID 5. SwitchName I have some data in this table. Now I want to update database. How to do this? I search for this but didn't get well answer I had tried it like: sampleDB = this.openOrCreateDatabase(SAMPLE_DBNAME, MODE_PRIVATE, null); ContentValues args = new ContentValues(); args.put(SwitchName, switchRename); Here I want to put SwitchName value as switchRename. Now I execute method as: sampleDB.update(SWITCH_TABLE_NAME, args, SwitchName +'menuItemName',null); But here second last argument (i.e where clause give me an error).In where clause I want as "SwitchName = 'xyz' " i.e where SwitchName is xyz. How to write this where condition correctly?
-- Kostya Vasilyev -- WiFi Manager + pretty widget -- http://kmansoft.wordpress.com --



Re: Update database

by pramod.deore » Fri, 03 Dec 2010 11:55:15 GMT


 Thanks Bibek and Kostya, problem is solved




-- 



Other Threads

1. Post subject: Store the data in raw folder of res directory

Hello,

My application has requirements to store or edit the file data in the
file which is available in Raw folder. Can some one tell me how it is
possible ?

I want to store the audio data in mp3 file which is available in res
folder.
--~--~---------~--~----~------------~-------~--~----~

2. Email Configuration - Compose activity

Hi All,

Is there anyway i can know is the email application configured correctly,
before i fire the intent?

Thanks

--~--~---------~--~----~------------~-------~--~----~

3. About music recording

4. How to order the items of GridView?

5. Android/G1 framebuffer driver

6. New Posting on funfashion4u (on 10 Apr 09)

7. Conversion to Dalvik format failed with error