vishnu suresh

vishnu suresh

  • NA
  • 53
  • 16k

problem in inserting multiple images to the database.

Jan 6 2015 9:18 AM
I have a database in which contain product details The product code, name etc are the columns, I have the product images in the system in a folder I need to add the images directly to the database according to the proper rows regarding the product code, The product code and images are sam, the product code is like 110-1,110-2 etc, and image names are 110-1jpg,110-2jpg etc I have a program but its not updating all the rows pls help                                            

DECLARE @CODE varchar

DECLARE image_cursor CURSOR FOR

SELECT CODE FROM MyMast WHERE img IS NULL

OPEN image_cursor;

FETCH NEXT FROM image_cursor

INTO @CODE;

WHILE @@FETCH_STATUS = 0

BEGIN

DECLARE @sql VARCHAR(MAX)

DECLARE @imagePath VARCHAR(255)

SET @imagePath = 'D:\images\' + RTRIM(LTRIM(@CODE)) + '.jpg'

SET @sql = 'UPDATE Mymast'

SET @sql = @sql + 'SET img = (SELECT BulkColumn FROM OPENROWSET( BULK ''' + @imagePath + ''', Single_Blob) AS Picture), SET PictureFileName = ' + @imagepath

SET @sql = @sql + 'WHERE CODE = ''' + @CODE + ''';'

BEGIN TRY

EXECUTE sp_executesql @sql

END TRY

BEGIN CATCH

END CATCH

FETCH NEXT FROM image_cursor

INTO @CODE;

END

CLOSE image_cursor;

DEALLOCATE image_cursor;

SELECT CODE, img FROM MyMast WHERE img IS NOT NULL


Answers (1)