LIKE Query Using Ms. Access And VB.Net

Hi everybody!

This time I want to share my experience about LIKE query on VB.Net using Ms.Access.

I developed an application with VB.Net (3.5 .Net Framework) which use Microsoft Office Access 2003 (mdb) as its database.

And my database provider is Microsoft.Jet.OLEDB.4.0.

The common LIKE query is like this :

SELECT coloumn_name(s) FROM table_name WHERE coloumn_name LIKE ‘%keyword%’

The “%” sign can be used to define wildcards (missing letters in the pattern) both before and after the pattern.

If you run your query on Ms.Access you have to use “*” symbol instead of “%”.

It will go something like this:

SELECT coloumn_name(s) FROM table_name WHERE coloumn_name LIKE ‘*keyword*’

I assumed that I can use the same query on my VB.Net application. But I was wrong 😐

We can’t use ‘*’ for LIKE query on VB.Net, even if it runs well on Ms.Access enviroment.

You have to use ‘%’ for your LIKE query on your project. Yes, it will look like this:

SELECT coloumn_name(s) FROM table_name WHERE coloumn_name LIKE ‘%keyword%’

For example:

SELECT id_movie, title_movie FROM movie WHERE title_movie LIKE ‘%war%’

The sample output:

id_movie title_movie
7 Star Wars Episode IV : A New Hope
9 Lord of War

Have fun!!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s