MikeR
11/26/2008 6:46:00 PM
Bob Barrows wrote:
> MikeR wrote:
>> Hi Bob - Now this is SERVICE. Thanks.
>>
>> Bob Barrows wrote:
>>> MikeR wrote:
>>>> I'm working on my first site using parameterized queries. I can't
>>>> find how to handle the fields for an INSERT, UPDATE or DELETE when
>>>> the values have an apostrophe, comma, or quote in them. i.e:
>>>>
>>>> str2qry = "qry_Update_Sta " & request.form("LastName") & ", " & _
>>>> request.form("Height") & ", " &
>>> This is not a parameterized query. It's basic dynamic sql. You need
>>> to pass the values as parameters, like this:
>>>
>>> Aconn.qry_Update_Sta request.form("LastName"), _
>>> request.form("Height")
>> ADODB.Connection (0x800A0E7C)
>> Parameter object is improperly defined. Inconsistent or incomplete
>> information was provided.
>> /nf4l/dir1/asp/updateDB_Action.asp, line 49
>>
>> AConn.qry_Update_Sta request.form("AdminCall"),
>> request.form("tower"), _ request.form("160M"), request.form("80M"),
>> request.form("40M"), _ request.form("20M"), request.form("15M"),
>> request.form("10M"), _ request.form("RxA"), request.form("Rig"),
>> request.form("Amp"), _ request.form("App"), request.form("EMail"),
>> request.form("club"), _ request.form("QTH"), request.form("URL"),
>> request.form("comment"), _ request.form("KeyCall")
>
> ok, you passed 18 values
>
>> The query is:
>> UPDATE Stations SET Call = [StaCall], Towers = [tower], M160 =
>> [160M], M80 = [80M], M40 = [40M], M20 = [20M], M15 = [15M], M10 =
>> [10M], RXAntennas = [RxA], Rigs = [Rig], AMPS = [AMP], ContestSW =
>> [App], [E-Mail] = [Email], ContestClub = [Club], Location = [QTH],
>> WebPage = [URL], Comments = [Comment], Updated = Date()
>> WHERE call=[UCALL];
>
> and the query expects (if those are all being treated as parameters) ...
> 17? Let's make sure:
>
> 1 [StaCall]
> 2 [tower]
> 3 [160M]
> 4 [80M]
> 5 [40M]
> 6 [20M]
> 7 [15M]
> 8 [10M]
> 9 [RxA]
> 10 [Rig]
> 11 [AMP]
> 12 [App]
> 13 [Email]
> 14 [Club]
> 15 [QTH]
> 16 [URL] I'm wondering if URL is a reserved keyword
> 17 [Comment]
> Date() not a parameter
> 18 [UCALL]
>
> Nope, I miscounted. So the parameters expected match the values
> supplied.
>
> Kinda tough to debug this one from where I'm sitting, but the first
> thing to do is to make sure none of those parameters have the same name
> as a database object (or reserved keyword) by prefixing them with a "p"
> (that's the technique i use - you may do whatever you like to achieve
> the same result):
> UPDATE Stations SET Call = [pStaCall], Towers = [ptower], ...
Done.
>
> Also, a couple of those field names look suspect, so you might want to
> enclose them with brackets as well.
All in brackets.
>
> Now run the query in Access and keep track of the order in which you are
> prompted for parameter values: that will be the same order in which you
> will need to supply them in the vbscript code.
Done. The record updated in Access. The only thing that would cough on the order is
the date, right? All the rest of the fields are text.
>
> Next, make sure your request form variables contain what you expect them
> to contain. I prefer to assign the values to local variables and
> validate the local variables.
I had the wrong names for some of the request.form variables, so a value of blank
(space or NULL?) was being sent to the query. After I fixed that, the DB updates
(assuming all the fields have a value)
To discover that, I iterated thru the forms collection. As a matter of curiosity, why
don't they appear in the same order as they are on the form that sends them?
Some of the variables may not contain a value, I'd want to set that field in the DB
to blank (or NULL). Do I need an Iif in the query in that case? Or?