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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VB and Database Place Holders

Status
Not open for further replies.

lbaker78

Technical User
Jul 20, 2005
17
GB
Hi All,

I am trying to write some info to an Access Db, it all works fine until the data it's adding contains a ' (single apostrophe!). It then bombs out because now the command line is fragmented.

I know in perl (and other languages I believe) you can use place holders to get around this issue where you substitute a ? and apply the data after the command line and as if by magic its all inserted correctly! :)

How can I do this in VB? The line of code I am using that is relevant is:


Code:
With cmdCommand
    .ActiveConnection = conConnection
    .CommandText = "SELECT * FROM library WHERE URL = '" & curfile & "';"
    .CommandType = adCmdText
End With

As I mentioned above, this works fine until the curfile variable contains a ' (for example - I'm not liking this)

TIA! :)
 
Please see faq709-1526 on why it is not a good idea to just double the apostrophe in production applications that have user input.
 
Like this?

CommandText = "SELECT * FROM library WHERE URL = ''" & curfile & "'';"

That doesnt seem to work either...
 
bjd4jc - thats exactly the sort of thing I want to avoid! :) - in this instance, curfile is created by the app, but as it just pulls up a filename, that file name could contain all sorts of nasties!
 
[tt]... WHERE URL = '" & replace(curfile,"'","''") & "'"[/tt]

- but the faq/method bjd4jc linked to is better.

Roy-Vidar
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top