Solved

Update sort order in asp page

Posted on 2011-09-12
2
317 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

This script will sweep a range of IP addresses (class c only, 255.255.255.0) and report to a log the version of office installed. What it does: 1.)      Creates log file in the directory the script is run from (if it doesn't already exist) 2.)      Sweep…
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

738 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