-1

I need to insert an image from a path in my computer (for example D:\th.jpg) into a MS SQL Server binary column with T-SQL and choose specific row with WHERE clause.

This column's name is Image with a datatype of varbinary(MAX) and my table name is Recipes.

Mostafa
  • 658
  • 7
  • 24
  • Where's you c# code? How are you reading the image and inserting it into the command? – gunr2171 Dec 23 '19 at 18:59
  • 2
    Note that BULK INSERT and OPENROWSET ... BULK read files on the SQL Server, or in network locations accessible from the SQL Server. Not from where your client program is running. – David Browne - Microsoft Dec 23 '19 at 19:12
  • Is this `D:\ ` drive connected to the machine on which SQL Server is running? A remote SQL Server **cannot** grab files from your own local `D:\ ` drive. .... – marc_s Dec 23 '19 at 19:12
  • I have edited my question and added to it. And my program and data base are locally running. – Mostafa Dec 23 '19 at 19:41
  • 1
    Can you use c# to write as well as read? in my opinion, opening SQL engine to access disks is something to avoid. Something like this - https://stackoverflow.com/questions/7324190/how-to-store-images-to-a-varbinarymax-column – Joe C Dec 23 '19 at 19:57
  • Sorry, I made a big mistake and I changed my question completely and I answered it myself. – Mostafa Dec 23 '19 at 21:22

1 Answers1

0
Update dbo.Recipes
Set Image = (SELECT * FROM OPENROWSET(BULK N'D:\th.jpg', SINGLE_BLOB) Image)
Where Id = 13
Mostafa
  • 658
  • 7
  • 24