Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Extra space added to a records data fields

Extra space added to a records data fields

Scheduled Pinned Locked Moved Visual Basic
databaseannouncement
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    Jlawrnce
    wrote on last edited by
    #1

    I'm getting a extra space added to a records fields when I update the record. This is a VB6 Access DB application. The only thing I can think of is the SQL strSQLEditCustomer = "UPDATE Customers SET ContactFirstName = ' " & txtFName.Text & " ' , ContactLastName = ' " & txtLName.Text & " ' , BillingAddress = ' " & txtAddress.Text & " ' , City = ' " & txtCity.Text & " ' , State = ' " & CboState.Text & " ' , PostalCode = ' " & CboZip.Text & " ' , PhoneNumber= ' " & txtPhone.Text & " ' , EmailAddress = ' " & txtEmailAddress.Text & " ' WHERE CustomerID = " & SearchCustID & " "

    J D P 3 Replies Last reply
    0
    • J Jlawrnce

      I'm getting a extra space added to a records fields when I update the record. This is a VB6 Access DB application. The only thing I can think of is the SQL strSQLEditCustomer = "UPDATE Customers SET ContactFirstName = ' " & txtFName.Text & " ' , ContactLastName = ' " & txtLName.Text & " ' , BillingAddress = ' " & txtAddress.Text & " ' , City = ' " & txtCity.Text & " ' , State = ' " & CboState.Text & " ' , PostalCode = ' " & CboZip.Text & " ' , PhoneNumber= ' " & txtPhone.Text & " ' , EmailAddress = ' " & txtEmailAddress.Text & " ' WHERE CustomerID = " & SearchCustID & " "

      J Offline
      J Offline
      Jlawrnce
      wrote on last edited by
      #2

      I figured it out. FYI for those who may come across the same problem in the SQL when filling a table field and your setting it = to a textbox, the ' " & textbox1.text & " ' will result in the space added to the beginning of the field. changing the SQL to '" & textbox1.Text & "' will fix the problem. Note the difference in the placement of the single quotes between the 2 examples.

      1 Reply Last reply
      0
      • J Jlawrnce

        I'm getting a extra space added to a records fields when I update the record. This is a VB6 Access DB application. The only thing I can think of is the SQL strSQLEditCustomer = "UPDATE Customers SET ContactFirstName = ' " & txtFName.Text & " ' , ContactLastName = ' " & txtLName.Text & " ' , BillingAddress = ' " & txtAddress.Text & " ' , City = ' " & txtCity.Text & " ' , State = ' " & CboState.Text & " ' , PostalCode = ' " & CboZip.Text & " ' , PhoneNumber= ' " & txtPhone.Text & " ' , EmailAddress = ' " & txtEmailAddress.Text & " ' WHERE CustomerID = " & SearchCustID & " "

        D Offline
        D Offline
        Dave Kreskowiak
        wrote on last edited by
        #3

        You wouldn't have to worry about this problem at all if you used parameterized queries. SQL Injection Attacks and Some Tips on How to Prevent Them[^] RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

        1 Reply Last reply
        0
        • J Jlawrnce

          I'm getting a extra space added to a records fields when I update the record. This is a VB6 Access DB application. The only thing I can think of is the SQL strSQLEditCustomer = "UPDATE Customers SET ContactFirstName = ' " & txtFName.Text & " ' , ContactLastName = ' " & txtLName.Text & " ' , BillingAddress = ' " & txtAddress.Text & " ' , City = ' " & txtCity.Text & " ' , State = ' " & CboState.Text & " ' , PostalCode = ' " & CboZip.Text & " ' , PhoneNumber= ' " & txtPhone.Text & " ' , EmailAddress = ' " & txtEmailAddress.Text & " ' WHERE CustomerID = " & SearchCustID & " "

          P Offline
          P Offline
          Pankaj Kulkarni
          wrote on last edited by
          #4

          Hi,

          Jlawrnce wrote:

          strSQLEditCustomer = "UPDATE Customers SET ContactFirstName = ' " & txtFName.Text & " ' , ContactLastName = ' " & txtLName.Text & " ' , BillingAddress = ' " & txtAddress.Text & " ' , City = ' " & txtCity.Text & " ' , State = ' " & CboState.Text & " ' , PostalCode = ' " & CboZip.Text & " ' , PhoneNumber= ' " & txtPhone.Text & " ' , EmailAddress = ' " & txtEmailAddress.Text & " ' WHERE CustomerID = " & SearchCustID & " "

          Use "Trim" method to supress the extra space from the controls like "UPDATE Customers SET ContactFirstName = '"& Trim(txtFName.Text) &"'" This will also help you. Pankaj Kulkarni

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups