Solved

Update sort order in asp page

Posted on 2011-09-12
2
311 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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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…
This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

743 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now