AJAX Reorderlist: adding new records to the database - what value to set for the Sort Order Field column?

Last post 07-02-2008 9:20 AM by fendtt62. 5 replies.

Sort Posts:

  • AJAX Reorderlist: adding new records to the database - what value to set for the Sort Order Field column?

    06-30-2008, 11:09 PM
    • Member
      point Member
    • doubleJ
    • Member since 07-01-2008, 2:59 AM
    • Posts 3

    Hi,

    I am really hoping someone can help me because I am stuck!

    I have a reorderlist that draws data from a SQL datasource.  It all works beautifully, I can drag and drop, the new sort order is posted back and saved in the database table.  My issue is that I don't know what to put for a value in my SortOrderID column when I add new records to the database.  I can't leave the field "NULL" because the items with a NULL won't sort.  I am hesitant to query the database for the MAX value of that column and add a "1" to it, then use that value for the new SortOrderID value in the new record.  What happens when 2 users are entering new records at exactly the same time and they both get the same value from that query?

    I am sure that others are adding new records and then updating the reorderlist.  Please, if you have any advice to give, I am very happy to test it out.

    Jillian

  • Re: AJAX Reorderlist: adding new records to the database - what value to set for the Sort Order Field column?

    07-01-2008, 12:49 AM

    Hi Jillian,

    Make the SortOrderID Column as Identity Column in the Database. So that When u insert new records in the

    DataBase. It normally inserts the new value in that Column. So u don't need to worry about whether 2 users

    are inserting the records at a time....

    Go thru the URL for Identity Column Settings in the Table..

    http://msdn.microsoft.com/en-us/library/aa933196(SQL.80).aspx

    Hope this helps...

    IF THIS POST HELPS YOU, CLICK MARK AS ANSWER

  • Re: AJAX Reorderlist: adding new records to the database - what value to set for the Sort Order Field column?

    07-01-2008, 11:08 AM
    • Member
      8 point Member
    • fendtt62
    • Member since 06-23-2008, 12:20 PM
    • Posts 27

    are you sorting by the SortOrderID or something else?

    Here's what I have: I have an ID (identity), some description of the object, and then an orderID.  When I populate the list I implement a counter that counts the items in the list. Then when I add an element to the list I give it an orderID of the (count + 1).

  • Re: AJAX Reorderlist: adding new records to the database - what value to set for the Sort Order Field column?

    07-01-2008, 11:47 PM
    • Member
      point Member
    • doubleJ
    • Member since 07-01-2008, 2:59 AM
    • Posts 3

    I did try to make the sort field the identity field, but when I tried to reorder the items, they wouldn't reorder because the identity column has to keep it's value.  I couldn't overwrite the value with the new sort order. 

    Thank you but I am still searching!

    Jillian

  • Re: AJAX Reorderlist: adding new records to the database - what value to set for the Sort Order Field column?

    07-01-2008, 11:51 PM
    • Member
      point Member
    • doubleJ
    • Member since 07-01-2008, 2:59 AM
    • Posts 3

    Hi,

    fendtt62:

    are you sorting by the SortOrderID or something else?

    Here's what I have: I have an ID (identity), some description of the object, and then an orderID.  When I populate the list I implement a counter that counts the items in the list. Then when I add an element to the list I give it an orderID of the (count + 1).

    That was my first idea, and I have one concern about it.  What happens if I have 2 users who are entering data at exactly the same moment, and they get the same counter #?  I know that the chances are slim, but I am trying to find something that will guarantee that each sort order ID will be unique. 

    Today a friend suggested that I query for the Primary Key, which is an INT, and use that id as the sort order ID.  I am going to see if that will work.

    In the meantime, I am still looking for some suggestions on this issue - 

    Jillian 

     

  • Re: AJAX Reorderlist: adding new records to the database - what value to set for the Sort Order Field column?

    07-02-2008, 9:20 AM
    • Member
      8 point Member
    • fendtt62
    • Member since 06-23-2008, 12:20 PM
    • Posts 27

     In my case if two users add an item at the same time they will both have the same orderID and will be ordered by name.  After I have binded the objects to the list I then go through and set there orderID in the DB. Once the page finishes the post back from the add button they will have increasing orderID's from the top down.

    I'm not sure how your going to use the Pkey, if it's not identity then you have to insert the key manually every time.  Your then back to the same problem, your not going to be able to tell if two people are adding at the same time, if they do and they both are trying to enter the same key one of them is going to get an error.

     I'm also kind of confused as to why you have two users doing stuff to the same list.  That doesn't make much sense, one user would reorder the way he/she likes and then on the next post back the new order will show up on the other user and then that user would change it to their liking and so on.  Or user 1 would add an item and user 2 would see that item and not like it and remove it and so on.

     

    Tim 

Page 1 of 1 (6 items)