G
G
German2019-09-21 16:23:08
SQL Server
German, 2019-09-21 16:23:08

How to insert an image into the database?

In Visual Studio 2019, I created a .mdf database and I want to add a picture to my table, I added an image type column with what SQL query can I add a .png or .jpg picture there so that I can then load it into a PictureBox in my WinForms form?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
K
Konstantin Tsvetkov, 2019-09-21
@mrjbom

OPENROWSET .

INSERT INTO myimages values (SELECT * FROM OPENROWSET(BULK 'C:\img\1.png', SINGLE_BLOB) as T1)

Examine the Image ClassFromStream(Stream) , namely Save(Stream, ImageFormat). With their help, they work with BLOB fields.

I
Ivan Shumov, 2019-09-21
@inoise

100500 times. You don't have to do that. Databases, especially relational, are not for this. Store pictures statically on the server, in files

W
wja36rus, 2019-09-21
@wja36rus

What is the purpose of storing the image? Write down the path to it and the name in the format images / name.jpg and the picture itself in the folder

D
Dimonchik, 2019-09-21
@dimonchik2013

storage of images in the database

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question