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 7589541
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T20:11:11+00:00 2026-05-30T20:11:11+00:00

In the below C++ code, i am updating a field of emp table based

  • 0

In the below C++ code, i am updating a field of emp table based on the search value. But this code is not working properly. I am getting output as aborted.

void UpdateData(string field_name,string updated_value,string search_value)
{
  stmt->createStatement("UPDATE emp SET :1=:2 where search=:3");
  stmt->setString(1,field_name);
  stmt->setString(2,updated_value);
  stmt->setString(3,search_value);
  stmt->executeUpdate();
}

In my program user will select which field they have to update and the selected field name is passed into function as field_name parameter. updated_value is the new value entered by the user and search_value is the search key to find the appropriate record.

If i do like
stmt->createStatement(“UPDATE emp SET field_name=:2 where search=:3”);

its working..

But the problem is, the field name will change according to user selection. How i can overcome this problem. Is there any other way ?

  • 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-05-30T20:11:12+00:00Added an answer on May 30, 2026 at 8:11 pm

    You can’t set the name of the field with the statement->setString() method; only the values of the variables can be bound like that.
    I know of only two solutions to achieve this (both aren’t particularly nice):

    1. Dynamically create the statement string

      string statement ="UPDATE emp SET " + fieldname + "=:1 where search=:2";
      
    2. Prepare individual statements, each affecting one field and choose at runtime

      const string STATEMENT_FIELD_CITY = "UPDATE emp SET CITY=:1 where search=:2";
      const string STATEMENT_FIELD_LAND = "UPDATE emp SET LAND=:1 where search=:2";
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I created this earlier on today, but it is not working. Location manager returns
The below code is working great for handling errors for text fields in my
I'm working on porting some ancient code (10.2 era) from NSCoding/plist based archiving to
In the below code I am updating IndexOrder by Id using TryUpdateModel. Below update
I'm wondering why my code is not updating the the ajax call when I
Solution found, see my comment below D5, odbc to mysql database This code: with
I'm updating my user's Twitter status using the simple code below. My problem is
Why would this not show #total as a decimal? The value of the inputs
Below code saying error incorreect syntax near Main INSERT INTO tbl ( 'Week', Main,
The below code is very simple. I have a jQuery autocomplete bound to an

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.