Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Reorder Items in sql database

Posted on 2008-10-02
7
Medium Priority
?
190 Views
Last Modified: 2013-11-27
Hi all, looking for some help on re-ordering.  I have a parent with several siblings, the siblings are ordered by a display_order field.  I need to be able to drop a NEW sibling in the middle and re-order the siblings accordingly...  I am thinking about making the display_order field go by 10's or 100's, and drop a new one in the middle, but I really don't like this solution and it would eventually fill up anyway.  I'm sure there is some GREAT code out there to help out with this, or at least some ideas on how to go about it.  I am doing this in Visual Studio 2005 VB.net.  They are adding the siblings in via a detailsview grid.

Thanks,
Randy
0
Comment
Question by:ratkinso666
[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
  • 4
  • 2
7 Comments
 
LVL 3

Accepted Solution

by:
chrios earned 2000 total points
ID: 22623902
Not really sql or VB specific, but this is how I would have done it.

Assuming you start with five siblings ordered 1,2,3,4,5

If you want to insert a new one after 2, just increase the number for all siblings above 2 by one, starting with the highest number (5) and going down to 3 (2+1).
5->6
4->5
3->4
The new ordering numbers are now 1,2,4,5,6
Add the new sibling with number 3 and you're done.


0
 
LVL 4

Expert Comment

by:GO-87
ID: 22623989
Instead of trying to manually insert numbers between existing numbers, which will eventually require renumbering (even if you were to use decimals, you'd eventually run out of numbers), why not implement the list in a simple Collection?
This would still require that you are able to identify the next (or previous) sibling when you're about to insert the new sibling
For example:
Private colSiblings As New Collection
Then you can insert a new sibling relative to its adjacent sibling, for example:
colSiblings.Add(argNewSibling,  , argBeforeSibling, )
or
colSiblings.Add(argNewSibling,  ,  , argAfterSibling)
0
 

Author Comment

by:ratkinso666
ID: 22624040
Sounds like a great idea, I like it.  Would I somehow do that in the ItemInserting section??  
0
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
LVL 4

Expert Comment

by:GO-87
ID: 22624409
Yes,
argNewSibling would be an object (or a number, or a string, ...) representing the new sibling; and argBeforeSibling (or argAfterSibling) would be the desired neighbour for the new sibling. Remember, if you've inserted the items as numbers, then you need to refer to numbers when you compare (and likewise, if you inserted strings, you need to compare against strings).
I hope that makes sense.
0
 

Author Comment

by:ratkinso666
ID: 22625112
coming along nicely, but what is the syntax to pass more than one value from the gridview to the detailsview??  I have two parameters (in the datakey names) in the gridview BA_ID, BA_DispOrder.  I need the BA_ID to pass to my next gridview and since it is my primary I have no problem using it, but I need the BA_DispOrder to know my selection from the gridview, after I get this last part I will be finished with this.  This is what I am trying to use in my Insert Parameters section:
<asp:ControlParameter ControlID="GridView2" Name="BA_DispOrder" PropertyName="SelectedValue"
                                                Type="Int32" />
I need it as my value, this works for the first parameter in a list, but I guess not for the secondary one??
Thanks,
Randy
0
 

Author Comment

by:ratkinso666
ID: 22625138
I know in the code behind I would get it like this:

        Dim NewOrder As String = (GridView2.SelectedDataKey.Values("BA_DispOrder").ToString())

so, I could run an update on this in the code behind, after I do my insert, but I would rather do it on the insert from the detailsview...
0
 

Author Closing Comment

by:ratkinso666
ID: 31502362
Thank you for the excellent help!!!
0

Featured Post

Automating Terraform w Jenkins & AWS CodeCommit

How to configure Jenkins and CodeCommit to allow users to easily create and destroy infrastructure using Terraform code.

Question has a verified solution.

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

After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

730 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