Solved

VB.net VFPOLEDB ALLTRIM Issue!

Posted on 2014-03-12
4
698 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
ID: 39923943
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
ID: 39923983
BINGO!!!

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

Thanks,
Mark
0
 
LVL 29

Expert Comment

by:Olaf Doschke
ID: 39925997
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
ID: 39926200
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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The object model of .Net can be overwhelming at times – so overwhelming that quite trivial tasks often take hours of research. In this case, the task at hand was to populate the datagrid from SQL Server database in Visual Studio 2008 Windows applica…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

863 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

25 Experts available now in Live!

Get 1:1 Help Now