Click here to Skip to main content
15,888,301 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
Hi I am using sql server table to store data
There is an file upload control and one text box for user
In fileupload he will choose file and in position text box he will enter position, and that position will be stored in column named 'position'
I want to check if user is uploading file and inserting into position on which some file already exist... if so I want to increase all positions by 1 which is larger than than position
can u suggest code
thanks
Posted
Comments
Thanks7872 14-Oct-13 8:53am    
Not at all clear. What do you mean by "increase all positions by 1 which is larger than position"?
JoCodes 14-Oct-13 12:01pm    
Please elaborate the question with what exactly you want

1 solution

you just write a stored procedure and check and update that in side that sp. You may use Business logic/service layer to do the same thing

SQL
create proc UpdateFilePosition
(
   @FileName varchar(10)
   ,@ProposedPosition int
)
AS
begin
  if exitsts(select * from MyPositionsTable WHERE FileName = @FileName AND Position = @ProposedPosition)
  begin
       UPDATE MyPositionsTable SET Position += 1 WHERE   FileName = @FileName AND Position >= @ProposedPosition;       
  end
  insert MyPositionsTable(FileName, Position) values (@FileName, @ProposedPosition); 

end


Stored procedure check the provided file name and position is exists in table or not if found then it increase all positions by 1 started from proposed position. That way the proposed position will be unique.
 
Share this answer
 

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