Handling Trailing Spaces with VFP Data and ADO.NET

When working with Visual FoxPro data in ADO.NET, you may be surprised to see trailing spaces at the end of your character data. Visual FoxPro automatically trims these trailing spaces in BROWSE windows and when binding to user interface controls, but .NET does not.

To address this issue, you can change your character fields to varchar fields (introduced in VFP 9.0). You can then write a quick utility to remove the trailing spaces from the character data.

If you can’t remove the extra spaces due to requirements in your Visual FoxPro applications that are accessing the same data, you can remove the spaces programmatically in your .NET applications by adding RTRIM() commands to your ADO.NET SELECT statements. For example:

SELECT employeeid, lastname, RTRIM(firstname) as FirstName, title, titleofcourtesy, birthdate, hiredate, address, city, region, postalcode, country, homephone, extension, photo, notes, reportsto FROM Employees

Best Regards,
Kevin McNeish
Chief Architect MM .NET Application Framework


One thought on “Handling Trailing Spaces with VFP Data and ADO.NET

  1. Hi,
    thanks for this tipp, this is exatly my problem, but your solution just dosn’t work for me. Not with RTRIM, not with ALLTRIM, the trailing spaces does not go away.

Leave a Reply

Your email address will not be published. Required fields are marked *