Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Search for ' as in a name like "O'Neil"

Status
Not open for further replies.

Ogi

Technical User
Nov 9, 2001
896
GB
Hi,

Not sure if this is in the correct section but as my issue is in VB6, thought I'd ask here!

Just wondering how to get round a name search when you store in the database "O'Neil" and want to do a search?

Obviously an Sql statement can't read:-

SELECT * FROM Customers WHERE Name Like 'O'Neil'

So what's the best way round it?

Cheers in advance,
Carl.
Also posted in VB6 Forum here!
 
Code:
SELECT * FROM Customers WHERE [Name] LIKE 'O'[red]'[/red]Neil'

Within an application though, I would prefer to use a parameter. It's been too long since I've done VB6, but here is VB.Net code. I'm sure you are able to do something similar in VB6.

Code:
SqlCommandInstance.CommandText = "SELECT * FROM Customers WHERE [Name] LIKE @Name"

SqlCommandInstance.Parameters.AddWithValue("@Name", SomeVariableHoldingO'Neil)
 
@name="O" + Chr("39") + "Neil"

@sqlstr= "SELECT * FROM Customers WHERE [Name] LIKE " + @Name


Simi
 
Just FYI this is a SQL Server (T-SQL) forum. There are other fora for VB 5 & 6: forum222

or VB.Net: forum796


Beir bua agus beannacht!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top