Re: Syntax for multiple WHERE in recordset?
- From: "Bob Butler" <tiredofit@xxxxxxxxxx>
- Date: Fri, 29 Jul 2005 08:13:02 -0700
"Kahuna" <none@xxxxxxxxxxxx> wrote in message
news:umQ$U0ElFHA.1968@xxxxxxxxxxxxxxxxxxxx
> Hi Folks
>
> Heres what I have (and this work fine BTW):
>
> rst_con_calc.Open "SELECT tbl_conversion.conv_to FROM tbl_conversion
> WHERE tbl_conversion.conv_from=" & "'" & cmb_content_from & "'" & "",
> cnn, adOpenDynamic, adLockReadOnly
>
> I need another two criteria in the WHERE clause but this syntax is
> pretty dark stuff! What I need is something like:
>
> WHERE tbl_conversion.conv_from=" & "'" & cmb_content_from & "'" &
> AND "_ "tbl_conversion.conv_to=" & "'" & cmb_content_to & "'" & AND "_
> "tbl_conversion.conv_typeconvert=" & "'"cmb_typ_conv &"'" & "", cnn,
> adOpenDynamic, adLockReadOnly
Have you tried it? Are you getting an error? the only thing I see wrong is
missing & by youyr line continuations but with the wrapping done by the
newsreader it's hard to read that part anyway.
Why do you have the single quotes separated out like that? In other words,
why would you write
WHERE tbl_conversion.conv_from=" & "'" & cmb_content_from & "'" & AND "
instead of
WHERE tbl_conversion.conv_from='" & cmb_content_from & "' AND "
(not that it matters much except for making it harder to read; I see this
often and have never understood where people get it from)
If your variables can potentially contain ' characters then you may want to
ensure that they don't cause a problem. The easiest way I've found is to
add a function to handle it:
WHERE tbl_conversion.conv_from=" & SQ(cmb_content_from) & _
" AND tbl_conversion.conv_to=" & SQ(cmb_content_to) & _
" AND tbl_conversion.conv_typeconvert=" & SQ(cmb_typ_conv)
public function SQ(byval TextIn As String) as String)
SQ="'" & replace(textin,"'","''") & "'"
end function
Either that or use ADO command objects with parameters (which are also
somewhat more secure as they guard against "SQL injection attacks")
--
Reply to the group so all can participate
VB.Net: "Fool me once..."
.
- Follow-Ups:
- Re: Syntax for multiple WHERE in recordset?
- From: Kahuna
- Re: Syntax for multiple WHERE in recordset?
- From: Jeff Johnson [MVP: VB]
- Re: Syntax for multiple WHERE in recordset?
- References:
- Syntax for multiple WHERE in recordset?
- From: Kahuna
- Syntax for multiple WHERE in recordset?
- Prev by Date: Syntax for multiple WHERE in recordset?
- Next by Date: Re: Syntax for multiple WHERE in recordset?
- Previous by thread: Syntax for multiple WHERE in recordset?
- Next by thread: Re: Syntax for multiple WHERE in recordset?
- Index(es):
Relevant Pages
|