Solved

VB.net VFPOLEDB ALLTRIM Issue!

Posted on 2014-03-12
4
681 Views
Last Modified: 2014-03-13
OK, so I'm using the VFPOLEDB Provider to connect to a FoxPro database...however when I use my select statement to pull data the ALLTRIM(Field) is NOT triming off the spaces??

conn.Open()
sSQLCommand = "SELECT alltrim(vec_code) AS vec_code, alltrim(tdaf_code) as tdaf_code, alltrim(returndesc) as returndesc  FROM tdbank_return_codes ORDER BY vec_code"
Dim command As New OleDb.OleDbCommand(sSQLCommand, conn)

Why?

Thanks,
Mark
0
Comment
Question by:smithmrk
  • 2
4 Comments
 
LVL 41

Accepted Solution

by:
pcelba earned 500 total points
Comment Utility
Character strings in DBF structure have fixed length so the trailing spaces are always there in strings shorter than maximum field length...

You have two options:
1) Trim the spaces at VB side - it will work for sure
2) Retrieve data as Varchar string (update the maximum string length from 50 to whatever you need up to 254 chars):

SELECT CAST(alltrim(vec_code) AS varchar(50)) AS vec_code, CAST(alltrim(tdaf_code) AS varchar(50)) as tdaf_code, CAST(alltrim(returndesc) AS varchar(50)) as returndesc  FROM ...

I am just not sure if it will work because I did not test this possibility yet....
0
 

Author Closing Comment

by:smithmrk
Comment Utility
BINGO!!!

CAST(ALLTRIM(Field)as varchar(50)) WORKED!!!!

Thanks,
Mark
0
 
LVL 29

Expert Comment

by:Olaf Doschke
Comment Utility
Using Select expression AS fieldalias VFP needs to infer the resulting field type for the new field and in cases this is just infered from the result type and length of the first result record, in other cases, like ALLTRIM(), VFP knows the max length can be the original field length and uses that, so ALLTRIM() seems not to work, as spaces are added, instead of resulting in a varchar field.

It's even more complex with expressions working on several fields, therefore CAST is recommended to specify the result field type you want. That's what works best to specify what you get without letting VFP infer or guess wrong.

Bye, Olaf.
0
 

Author Comment

by:smithmrk
Comment Utility
Thanks Olaf!

That helps explain whats going on...it was driving me crazy for half the day yesterday.
I appreciate it!

Mark
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
This video discusses moving either the default database or any database to a new volume.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now