Solved

Update sort order in asp page

Posted on 2011-09-12
2
315 Views
Last Modified: 2012-08-13
After a user uploads a photo for a gallery, i collect the file name and sort order in an Access database.  I have the sort order 0.  There are about 60 images in the table.  After the new record is added, i want to update the sort order for all the records, making the one i just added the one on top, so i'm using the following code.  It updates the record to "1" that i added as 0 and adds 1 to each succeeding record.  But the record that is "1" doesn't get updated but all the rest do.  so then i have 1, 1, 2, 3, etc.  Two number ones. What's up with that?  I've been jacking around with this, trying to refresh, even setting up another page to update the sort order separately.  Why would it add +1 to all of the records except the original #1?  What am i missing?  Thanks in advance.
Set rs2 = Server.CreateObject("ADODB.Recordset")
	Dim strTableName2
	strTableName2 = "xmlContents"
	rs2.Open strTableName2 & " WHERE xmlCatid=" & request.querystring("catid") & " order by xmlSortOrder", objConn, adOpenForwardOnly, adLockOptimistic, adCmdTable
	rs2("xmlSortOrder")=rs2("xmlSortOrder") + 1
	rs2.Update

Open in new window

0
Comment
Question by:meldraper
2 Comments
 
LVL 15

Accepted Solution

by:
pateljitu earned 250 total points
ID: 36529957
As per your code description it seems that you ADD the records first and later do the update, in which case when you ADD the new records whats the xmlSortOrder sequence does it start from 0 if that is the case you would run into this problem. Would suggest perform the update statement first, grab the MAX xmlSortOrder and later execute the insert statement adding order as MAX xmlSortOrder + 1.


Also please provide complete code sample to help you debug the issue.
0
 
LVL 44

Expert Comment

by:GRayL
ID: 36530234
Update the sort order first.  Then insert the single record during which you set the value of xmlSortOrder to 0.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When it comes to writing scripts for a Client/Server computing environment it is essential to consider some way of enabling the authentication functionality within a script. This sort of consideration mainly comes into the picture when we are dealin…
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question