Error on an select statement "LIKE 'AC* %' in a VB.Net datatable

Hi

I get an error from a datatable select statement which contains a LIKE clause reading "... LIKE 'AC* %' ..."

The error reads "the string pattern AC* % is invalid".

Why ? * is not a wild card, so where is the problem ?

My application is written in VB.Net (VS 2013), it runs on Windows Server 2008 R2.
The same statement has worked on about another 400 selects with other data, where the part before the space did not have a * at the end.

Thanks for help
Bernard
LVL 1
bthouinIT Analyst and developerAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Paul MacDonaldDirector, Information SystemsCommented:
I suspect there's something else syntactically wrong here.  Can you post more of your query?
käµfm³d 👽Commented:
What do you mean by "datatable"? Do you mean:  DataTable? If so, then both ? and * are wildcards.

https://msdn.microsoft.com/en-us/library/system.data.datacolumn.expression(v=vs.110).aspx
Both the * and % can be used interchangeably for wildcard characters in a LIKE comparison. If the string in a LIKE clause contains a * or %, those characters should be enclosed in brackets ([]).

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Paul MacDonaldDirector, Information SystemsCommented:
A simple...
SELECT * from TABLE WHERE SomeColumn LIKE 'AC* %'
...works fine for me, but there's no harm in trying...
SELECT * from TABLE WHERE SomeColumn LIKE 'AC[*] %'
Become a CompTIA Certified Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

Fernando SotoRetiredCommented:
Try just using one or the other, LIKE 'AC*' or LIKE 'AC%', I believe they both have the same meaning in a DataTable object.
bthouinIT Analyst and developerAuthor Commented:
@käµfm³d
Yes, I mean a DataTable within a DataSet, and a DataSet.Tables(DataTable).Select("< SQL where clause>"). And thanks for the link. Once more, the help for this is somewhere where you'd never look for it. I searched obviously for the LIKE clause, where I didn't find anything, because * is not a W3c standard wild cards. Why MS has it for a DataTable Select, but doesn't have it in T-SQL will remain an angering mystery. Maybe because Access uses it ?
You get thalf the points.

@paulmacd
I suspected the bracketing could be the answer, but I was not sure, hence my question. Thanks.
You get half the points.

@Fernando
No, I precisely do not want 'AC* or 'AC%', because my Select was looking for a string beginning with the 3 characters 'AC*' followed by a space, so fixedly the string 'AC* ' and whatever follows, hence the 'AC* %' I ended up with, which confused MS's DataTable Select LIKE logic...
käµfm³d 👽Commented:
Once more, the help for this is somewhere where you'd never look for it. I searched obviously for the LIKE clause, where I didn't find anything, because * is not a W3c standard wild cards.
For your reference, the way that I found the documentation was that I started with the DataTable documentation, scrolled down to the Select documentation link, then, buried within that documentation page is a link to the Expression documentation, which is what I linked to above. So from my perspective, it is where I'd expect it to be.

Every once in a while some things get lost or buried in MS' documentation of the Framework. But in my experience, they usually do a good job of hyperlinking to related content (like with the Expression bit).
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.