Notices
Computer & Technology Related Post here for help and discussion of computing and related technology. Internet, TVs, phones, consoles, computers, tablets and any other gadgets.

ASP Experts - Update problem - help please!!!

Thread Tools
 
Search this Thread
 
Old 06 March 2002, 11:43 AM
  #1  
Dream Weaver
Scooby Regular
Thread Starter
 
Dream Weaver's Avatar
 
Join Date: Feb 2000
Location: Lancashire
Posts: 9,844
Received 0 Likes on 0 Posts
Unhappy

Calling the ASP crew. How can I use a "where" clause in the following update statement.

' Recordset object
Dim rspic
Set rspic = Server.CreateObject("ADODB.Recordset")

rspic.Open "Files", connStr, 1, 3, 2
rspic("fileName") = fileName
rspic("fileData").AppendChunk fileData
rspic("contentType") = contentType
rspic("carid") = passid
rspic.Update

rspic.Close
Set rspic = Nothing

The page uses a Loader class to create a scripting dictionary which holds the binary data from the uploaded image. The variables have been declared at the top of the page.

This page is intended to update the image if the wrong one has been submitted, or if it needs changing. Therefore, the user clicks on "Change Picture" and can then re-select a new image to insert into the DB. The table "Files" holds all the images, and links to the "Cars" table via carid.

What I am trying to say in the statement is "Update the record in 'Files' where carid = passid" passid is the id of the car passed from the initial page. Currently it works for the first record, but then gives the following error for subsequent records:

Microsoft JET Database Engine error '80040e21'

The changes you requested to the table were not successful because they would create duplicate values in the index, primary key, or relationship. Change the data in the field or fields that contain duplicate data, remove the index, or redefine the index to permit duplicate entries and try again.

/process_updateimage.asp, line 75


From this I presume it is trying to replace the carid value, and the DB wont let it. However I want it to replace the value with the same number (passid) so it should work. I have tried the update statement without the carid line, but it justs changes the picture of the first record.

Help please - doing my head in.

DW
Old 06 March 2002, 12:16 PM
  #2  
chiark
Scooby Regular
 
chiark's Avatar
 
Join Date: Jun 2000
Posts: 13,735
Likes: 0
Received 0 Likes on 0 Posts
Post

also, add another "," to the open command to make sure that it's not thinking that "1" is the activeConnection
Old 06 March 2002, 12:28 PM
  #3  
Fosters
Scooby Regular
 
Fosters's Avatar
 
Join Date: Jul 2000
Location: Islington
Posts: 2,145
Likes: 0
Received 0 Likes on 0 Posts
Post

looks too complicated. do this instead...

dim rs
dim sSQL
dim sCDT

set rs = Server.CreateObject("ADODB.command")

sSQL="Update table set field1='1',field2 = '2' where blah=blah and whatever=1"

rs.activeconnection = cn
rs.commandtype = &H0001
rs.commandtext = sSQL
rs.execute

set rs=nothing

cn.close
set cn=nothing
Old 06 March 2002, 12:55 PM
  #4  
chiark
Scooby Regular
 
chiark's Avatar
 
Join Date: Jun 2000
Posts: 13,735
Likes: 0
Received 0 Likes on 0 Posts
Post

...apart from the fact that there's binary data in a field, so that would be "interesting" to write using a sql statement

I do agree tho - SQL statements are easier to get your head around and don't rely on you having the right type of recordset open.

Nick.
Old 06 March 2002, 12:59 PM
  #5  
Dream Weaver
Scooby Regular
Thread Starter
 
Dream Weaver's Avatar
 
Join Date: Feb 2000
Location: Lancashire
Posts: 9,844
Received 0 Likes on 0 Posts
Unhappy

Thanks, but still cant get it to work.

Fosters - where do I need to put the connection to the DB? Also what do I do with the .AppendChunk bit - can it be added as a value into the field?

Hard work this ASP malarky.
Old 06 March 2002, 01:41 PM
  #6  
Dream Weaver
Scooby Regular
Thread Starter
 
Dream Weaver's Avatar
 
Join Date: Feb 2000
Location: Lancashire
Posts: 9,844
Received 0 Likes on 0 Posts
Thumbs up

OK Nearly there - yeehaa!!!

I have got it to work now, by adding rspic.Filter after rspic.Open. Hence it filters out the files by using rspic.Filter = "carid = passid".

Only problem is it only works when I type a number in for passid. So if I type 70 into the script it updates car 70, 69 car 69 etc.

Just cant get it to take the value from the variable passid - I will though, oh yes I will

DW
Old 06 March 2002, 01:44 PM
  #7  
Fosters
Scooby Regular
 
Fosters's Avatar
 
Join Date: Jul 2000
Location: Islington
Posts: 2,145
Likes: 0
Received 0 Likes on 0 Posts
Post

Chiark's wise. his way is better.

what db are you using? if you can use stored procedures, they're the way to go on this sort of thing.

Being an update I would have thought that it wouldn't matter what you were writing, which makes me suspect the recordset open parms.

Try the open parms I've specified below (they might be the ones you already have - I just don't have the numbers!)

rs.Open "Files", connstr, adOpenForwardOnly, adLockOptimistic, adCmdTable
Old 06 March 2002, 02:00 PM
  #8  
chiark
Scooby Regular
 
chiark's Avatar
 
Join Date: Jun 2000
Posts: 13,735
Likes: 0
Received 0 Likes on 0 Posts
Post

...if there's a difficult way of doing something, you'll find it, eh Si?

Old 06 March 2002, 02:59 PM
  #9  
Dream Weaver
Scooby Regular
Thread Starter
 
Dream Weaver's Avatar
 
Join Date: Feb 2000
Location: Lancashire
Posts: 9,844
Received 0 Likes on 0 Posts
Thumbs up

What do you mean difficult

Anyway, all sorted now - out of interest here is the solution I have found:

' Recordset object
Dim rspic
Set rspic = Server.CreateObject("ADODB.Recordset")

rspic.Open "Files", connStr, 1, 3, 2

rspic.Filter = "carid = " & passid

rspic("fileName") = fileName
rspic("fileData").AppendChunk fileData
rspic("contentType") = contentType

rspic.Update

rspic.Close
Set rspic = Nothing

Thanks for the help guys

DW
Old 03 June 2002, 12:14 PM
  #10  
chiark
Scooby Regular
 
chiark's Avatar
 
Join Date: Jun 2000
Posts: 13,735
Likes: 0
Received 0 Likes on 0 Posts
Post

DW,

change the recordset to open with "SELECT * from FILES WHERE CARID=" & request("passid")
or whatever...

Cheers,

Nick.

[Edited by chiark - 3/6/2002 12:15:26 PM]
Related Topics
Thread
Thread Starter
Forum
Replies
Last Post
Darrell@Scoobyworx
Trader Announcements
26
30 January 2024 01:27 PM
PetrolHeadKid
Driving Dynamics
10
05 October 2015 05:19 PM
An0n0m0us
Computer & Technology Related
0
28 September 2015 09:58 PM
MightyArsenal
Wheels, Tyres & Brakes
6
25 September 2015 08:31 PM



Quick Reply: ASP Experts - Update problem - help please!!!



All times are GMT +1. The time now is 02:28 PM.