Solved

Update sort order in asp page

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

I met Paul Devereux (@pdevereux) today when I responded to his tweet asking “Anybody know how to automate adding files from disk to a folder in #outlook  ?”.  I replied back and told Paul that using automation, in this case scripting, to add files t…
Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

803 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