asp.net update rows using for loop?

y0ger_19

New member
I'm making a photo gallery where you the admin can control the order on which the end user will view the gallery. For example there are 5 pictures in the Database ordered 1-5 and I want to add a 6th picture and place it in the 3rd position in the ordering. So the excisting entry numbered 3rd in the order would become 4, 4th would become 5th and 5th would turn to 6th to end the loop. I decided using a for loop on rearranging the order, after the later numbers are moved I would then input the newly added data. Here is my codes but what I get is that all numbers that are suppose to be arranged all become the highest number in the ordering. Using the same example from above in inputing the new entry in the 3rd position the exciting entries from 3-5 all become 6. May you help me fix the code.

' input is the position the new entry will be placed
' plusone is the new number in the ordering that is supposed to be saved
For counter = input To intPicOrder
Label4.Text = counter
myConnection.Close()
MyCommand.CommandText = "UPDATE photo SET PicOrder = " & Integer.Parse(plusone).ToString & " WHERE PicOrder ='" & Label4.Text & "'And FKCategoryId ='" & cmbCategory.SelectedItem.Value & "' "
MyCommand.Connection = myConnection
MyCommand.Connection.Open()
MyCommand.ExecuteNonQuery()
MyCommand.Dispose()
MyReader.Close()
plusone = plusone + 1
Next counter

' Adding the new record to the database
UpdateGallery(cmbCategory.SelectedValue, strFileName, cmbVisible.SelectedValue, input)
lblUploadMessage.Visible = True
lblUploadMessage.Text = "Image uploaded successfully..."
 
Back
Top