Re: SQL SELECt with ' in filter name




"Khalid Rahaman" <KhalidRahaman@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:972A1E89-6FCB-47AA-921B-3BB6977EB8B0@xxxxxxxxxxxxxxxx
I am trying to filter a recordset using the following SQL statement

SELECT * FROM 'cars.sold' where seller='" & txtSellername.text & "'"

the txtsellername.text refers to a texbox on the VB form which enters the
name i want to filter by.

This works great for everything except when the variable contains an ' in
the textbox for example "Joe's Auto".

You need to parse txtSellername.text and double up single quotes when
present.
It would be easy to write a VB function that does this

FUNCTION SQLEscape$(Intext$)
'code here
END FUNCTION

and then do

SELECT * FROM 'cars.sold' where seller='" & SQLEscape(txtSellername.text) &
"'"

Stephen Howe


.



Relevant Pages

  • Re: SQL SELECt with in filter name
    ... the txtsellername.text refers to a texbox on the VB form which enters ... the name i want to filter by. ... Please reply to the newsgroup. ...
    (microsoft.public.data.ado)
  • Re: SQL SELECt with in filter name
    ... the txtsellername.text refers to a texbox on the VB form which enters the ... name i want to filter by. ... the textbox for example "Joe's Auto". ...
    (microsoft.public.data.ado)
  • Re: Capture source filter wrapper
    ... I find it hard to believe WMP is asking for this IID, ... it refers to IDirectVobSub: ... the filter graph"... ...
    (microsoft.public.win32.programmer.directx.video)
  • Re: Filtering records using SQL statement with in field name
    ... You need to double up the single quote mark. ... the txtsellername.text refers to a texbox on the VB form which enters the ... Al Reid ...
    (microsoft.public.vb.database)