vishnu suresh

vishnu suresh

  • NA
  • 53
  • 16.1k

inserting images to the correct id

Jan 3 2015 5:11 AM

In my program I want to insert the images of students which are in a folder to the sql table according to id. Currently I used this querry.

declare EmployeCursor cursor fast_forward for


select num


from login


declare @sql nvarchar(4000)


declare @num nvarchar(50)


open EmployeCursor


while (1=1) begin


fetch next from EmployeCursor into @num


if @@FETCH_STATUS<>0 break


set @sql = N'UPDATE login




SET image =


(SELECT * FROM



OPENROWSET(BULK N''D:\img\' + cast(@num as nvarchar(50)) + N'.jpg'', SINGLE_BLOB) AS img)


WHERE num = ' + cast(@num as nvarchar(max))


exec(@sql)


end /* while */


close EmployeCursor


deallocate EmployeCursor

 But its have problem.My image names are in the format 12-1.jpg and id in the format 12/1. so how can I add images? pls help
 


Answers (13)