Hey team, i'm having a problem with this query,

"SELECT * FROM marketingDB WHERE company_name LIKE 'allied' & '*'"

the program ive written runs fine and it doesnt show any problem with the query infact the exact same query works fine on access but when i put it on vb the datagrid comes back empty and I believe the datagrid works as with other simpler queries it returns stuff. The database is called vbDataBase and the table im, attempting to read from is called marketingDB.

The naming of everything is fine because it builds the program fine, post the whole code below;

'TODO: This line of code loads data into the 'VbDataBaseDataSet.marketingDB' table. You can move, or remove it, as needed.
        Me.MarketingDBTableAdapter.Fill(Me.VbDataBaseDataSet.marketingDB)

        Dim cn As New OledbConnection()
        cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\\Wise-fps01\shared\vbDataBase.mdb"
        cn.Open()

        Dim command As OleDbCommand = New OleDbCommand("SELECT * FROM marketingDB WHERE company_name LIKE 'allied' & '*' ", cn)
        command.CommandType = CommandType.Text

        Dim adapter As OleDbDataAdapter = New OleDbDataAdapter(command)

        Dim table As New DataTable

        adapter.Fill(table)
        cn.Close()


        DataGridView1.DataSource = table
        DataGridView1.Update()

Any help you can give me would be greatly appreciated, I will post any other data you need. Just let me know.

Thanks,andrew

"SELECT * FROM marketingDB WHERE company_name LIKE 'allied' & '*'"

is wrong what are you trying to do?

first of you can't do this company_name LIKE 'allied' & '*' what you would do is

SELECT * FROM marketingDB WHERE company_name LIKE 'allied' AND company_name Like '*'

I believe * is used to get wildcard values in Access so I guess you are trying to get all values that that with allied

in that case it should look like this

SELECT * FROM marketingDB WHERE company_name LIKE 'allied*'

really because if i type what i had in first time round through access it retrieves the records alright :/ Because what i want it to do is return all of the company names that have allied in it

SELECT * FROM marketingDB WHERE company_name LIKE 'allied' & '*'

returns all of the companies that have allied in the title, but in vb it seems to have an issue with it

did you try this?

Dim command As OleDbCommand = New OleDbCommand("SELECT * FROM marketingDB WHERE company_name LIKE 'allied*'", cn)

cause that's all I see wrong with your code.

Hi Andrew. Use % instead of * for your wildcard

"SELECT * FROM marketingDB WHERE company_name LIKE 'allied' & '%' "

Or maybe better without so many single quotes:

"SELECT * FROM marketingDB WHERE company_name LIKE 'allied%' "

THe problem is a known irritation regarding oledb, access, jet and sql conventions. Google "oledb wildcard" if only to see you are not alone!

Hey team, i've tried a couple of the ideas you've said but by putting a % in the query string does that not mean ill be looking for a company thats like allied%? instead of just allied? The star wildcard thing works in access so i figured as im using an access connection. The %,however, doesnt work in access so is the % the wildcard in vb?

Thanks for all the post, and its nice to see so many people have been doing the same thing :P

Well team, I put the % in and it worked, i guess i thought that if it didnt work in access then it would give me an error in vb but it doesnt lmao

Thanks again for you help, all of you!

Just for people who wanna know it looks like :

SELECT * FROM marketingDB WHERE company_name like 'allied%'

LLAP team!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.