How can I easily insert a blob into a varbinary(MAX)
field?
As an example:
thing I want to insert is: c:\picture.png
the table is mytable
the column is mypictureblob
the place is recid=1
1) Bring up SQL Server Management Studio. 2) Connect, and open the database you want to add the image to. 3) Expand the tables, and either add a new table with an appropriate index field, or right click teh table and select design. 4) Add a field called "myImage", and make its datatype "image".
Use the following TSQL statement: USE master; GO CREATE DATABASE Test; GO USE Test; GO CREATE TABLE BLOBTest ( TestID int IDENTITY(1,1), BLOBName varChar(50), BLOBData varBinary(MAX) ); In this example, the column name is BLOBData, but the column name can be any standard SQL name.
You can insert into a varbinary(max) field using T-SQL within SQL Server Management Studio and in particular using the OPENROWSET commmand.
For example:
INSERT Production.ProductPhoto ( ThumbnailPhoto, ThumbnailPhotoFilePath, LargePhoto, LargePhotoFilePath ) SELECT ThumbnailPhoto.*, null, null, N'tricycle_pink.gif' FROM OPENROWSET (BULK 'c:\images\tricycle.jpg', SINGLE_BLOB) ThumbnailPhoto
Take a look at the following documentation for a good example/walkthrough
Working With Large Value Types
Note that the file path in this case is relative to the targeted SQL server and not your client running this command.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With