Click here to Skip to main content
15,886,083 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi coder i just want to know is this possible to insert an image into database before any other image in the database.

Suppose i have file-up loader to upload image and a drop-down list to show priority of those images.
now i have 10 images in my database and i bind, priority with the drop-down list. Now When i upload new image i can see priority of images into drop-down list. Now that part is been done

Now what i want is when i upload new image and select priority from the drop-down list that image store in the database before the priority of the image in the database.
example:
i select file-up loader button to upload file and select priority number 5 from the drop-down list.
now that image will store at priority number 5 and image which is at priority number 5 now have priority number 6 and so on..

How can i do that
Thanks in advance
Posted
Updated 19-Jun-13 2:34am
v3

1 solution

No.

Databases do not have to return items in any particular order unless you explicitly specify it in the SELECT statement with an ORDER BY clause. If you do not add an ORDER BY clause, then records will be returned in whatever order is convenient to the database engine at that moment. Normally, this is the order in which it encounters them in the database store file, which tends to be in the order they were inserted to the database - but it doesn't have to be. Deleting records will leave "gaps" which it can fill if it wants to, or it may reorder records completely hwne it compacts the file(s) providing the backing stores.

If you want a specific order, then you have to have a column in the table that allows you to use an ORDER BY clause on the table.
 
Share this answer
 
Comments
amitesh1989 19-Jun-13 9:12am    
i am using priority as SELECT COUNT(Priority) as Tot FROM TestImages
and i am showing those images in gridview using select * from TestImages order by Priority asc
so now can i do that
OriginalGriff 19-Jun-13 9:16am    
Alter the values of your priority column for all images you want after the new one.
amitesh1989 19-Jun-13 9:19am    
i want when i upload new image it will add before the selected priority which i select from the dropdown list the image which is present at that priority move down and so as the other images
OriginalGriff 19-Jun-13 10:34am    
Yes - you have to use an update statement on each of the images which you want after the new one.
There is no automatic "insert and renumber" operation.
amitesh1989 20-Jun-13 4:18am    
i use update query like this
const string query = "Update imagesTable set Priority = Priority + 1 where Priority >= @Priority;" +
"insert into imagesTable (ImageName, Description, Path, Priority) values (@ImageName, @Description, @Path, @Priority)";

it will update as well as insert but it will not insert at the selected priority from the dropdown list it will add at the last and update the priority

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900