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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T17:28:17+00:00 2026-05-25T17:28:17+00:00

When I update a field in my MySQL database, it always adds a whitespace

  • 0

When I update a field in my MySQL database, it always adds a whitespace to the value.
I tried to remove the whitespace with the trim-command and the replace-command. Neither of them worked. So I expect that it isn’t a whitespace but some vague ASCII character. These are the commands I used:

this.foo = result.GetValue(0).ToString().Trim();
this.bar = result.GetValue(0).ToString().Replace(" ","");

The field it updates is a VARCHAR(xx). This is my MySQL update command:

            MySqlCommand cmd = new MySqlCommand("UPDATE " + table + " SET " + new_field + " =' " + new_value+ "' WHERE " + field+ "= " + value + "",this.con);

this.con is my connection to the MySQL database.

FYI: I use .NET 3.5CF with a mysql.data.cf DLL in Visual Studio 2008.

Could someone help me out with this problem? It’s driving me nuts.

  • 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-25T17:28:18+00:00Added an answer on May 25, 2026 at 5:28 pm

    Well yes, you’ve got a leading space in the SQL:

    "UPDATE " + table + " SET " + new_field + " =' " + new_value+ "'
    

    Note the bit straight after “=” – you’ve got a quote, then a space, then new_value.

    However, you shouldn’t be putting the values in the SQL directly in the first place – you should be using parameterized SQL statements… currently you’ve got a SQL injection attack waiting to happen, as well as potential problems for honest values with quotes in.

    You should use parameterized SQL for both new_value and value here… I’m assuming that field and table come from more “trusted” sources?

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

Sidebar

Related Questions

I've been trying to update a field in MySQL database but I'm getting an
How can I insert a NULL value into a database field (MySQL) with char(2)?
How to edit unique field value in mysql database? if I edit it in
I have a MySQL database in which I have to update a certain field
How does one properly update a mysql field with a NULL value when using
I have to update a field in the MySQL database on each HTTP request
I need to update a field (called updated_at ). The field in MySQL is
I'm trying to update a field in the database to the sum of its
I've got a field in a mysql database that contains prices for a store.
In my MySQL database, I have the following column type. Field | Type |

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.