Extra space added to a records data fields
-
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 & " "
-
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 & " "
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.
-
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 & " "
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
-
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 & " "
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