Create a Stored Procedure:
Procedure InsertFile
Parameter: @FileName
Begin
If @FileName Exists
Begin
@Counter = GetNextNumber()
@FileName = @FileName + @Counter
End
Insert Into FileTable @FileName
Select * From FileTable Where FileName = @FileName <-- This line is
important
End
So in your application:
1) execute the above procedure and fill out some DataTable
2) In that DataTable you will be getting the Row which is just inserted
3) Get the file name from that DataTable and save file with that Name
Regards,
Arsalan Tamiz
On Sat, Nov 22, 2008 at 9:19 AM, BigJ <[EMAIL PROTECTED]> wrote:
>
> I'm using the FileUpload control to upload images to my image folder,
> storing the pathway to the image in table. My primary key is the
> imagePath column My question is, how do you detect if an image
> already exists in the table, and if so how to alter the name like
> image/mypic.jpg and image/mpic(2).jpg , so on and so forth.
>
> I came up with the initial idea of adding an imageCnt column
> (equivalent of a counter) using the SqlDataSource control to get the
> latest version of the image like so:
>
> SelectCommand="SELECT MAX(ImageCnt) FROM userImages WHERE
> ImagePath LIKE @ImagePath"
>
> I was going to then the result of that to decide what number to append
> to the image. However the problem is how do I grab that ImageCnt
> value before the insert action is attempted? Any insight is
> appreciated...thanks.
>
> Thanks
>
> Jon