Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7880697
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T04:12:20+00:00 2026-06-03T04:12:20+00:00

Hi all I want to update a row on clicking on update button,but its

  • 0

Hi all I want to update a row on clicking on update button,but its doesn’t work.
I have used following code.

 public void btnUpdate(View v) { 
handeler.updateData(updateName.getText().toString(), updatePhone .getText().toString(), updateEmail.getText().toString(),id);
 } 

public void updateData(String name, String phone, String email, String id) {
 ContentValues values = new ContentValues(); 
values.put(COLUMN_FIRST, name); 
values.put(COLUMN_SECOND, phone); values.put(COLUMN_THIRD, email); database.update(TABLE_NAME, values, id, null); 
} 
public void search() {
        Cursor cursor = handeler.getData();
        if (cursor.moveToFirst()) {
            String phoneNo;
            phoneNo = updateByPhone.getText().toString();
            do {
                String s1 = cursor.getString(2);
                if (phoneNo.compareTo(s1) == 0) {
                    id = cursor.getString(0);
                    updateName.setText(cursor.getString(1));
                    updateEmail.setText(cursor.getString(3));
                    updatePhone.setText(cursor.getString(2));

                }
            } while (cursor.moveToNext());

        }

    }

So if any know please suggest me how to solve it.
Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T04:12:21+00:00Added an answer on June 3, 2026 at 4:12 am

    I see a couple possible issues:

    1) You have an extra space updatePhone .getText().toString() should be updatePhone.getText().toString()

    2) you are passing a variable id from btnUpdate to updateData but it is not clear where it is coming from (or even if it actually exists)

    My bet is that #2 is your issue. You probably need to pass the id (I assume that’s meant to be the RowId you want to modify in the db) in to the btnUpdate method:

    public void btnUpdate(View v, long id)    
    

    There are other possibilities… you haven’t shown your DB structure, so it could be that some constraint is causing the update to fail.

    EDIT

    The update method docs show this:

    public int update (String table, ContentValues values, String whereClause, String[] whereArgs)
    

    Note the part String whereClause. That’s supposed to be a SQL WHERE statement (without the WHERE). You are only passing in the id, not a WHERE clause. Change your call to update to make that a WHERE clause and it should work. A couple of examples:

    database.update(TABLE_NAME, values, "_id = " + id, null); 
    
    database.update(TABLE_NAME, values, "_id = '" + id + "'", null); 
    

    Both examples assume your row id column is labeled _id.

    The first example is if id is an integer value. The issue there is that you are setting id as a string, so I’m unsure if this is the case or not. If it is supposed to be an int, you should get it using id = cursor.getInt(0); instead of id = cursor.getString(0);.

    If it truly is a string and not an int, use the second version, which encloses id in single quotes to indicate it is a string.

    Hope this helps!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an ORM mapped object, that I want to update. I have all
I want to update a row in a table, updating all the columns to
I want to update my MYSQL table, but with a condition. I have a
I want to update a mysql row, but I do not want to specify
I have a tsvector column that I want to update when the row changes.
I have a table which I want to update a single row in after
What I want: Update all new commits from server with my local repository in
i want to update all records in my database(mongodb),I tried to use command below
I want to select multiple rows from checkbox and want to update them all
I want to perform an update on all the rows in an XML column

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.