question

PriyanthaNiroshan-3377 avatar image
0 Votes"
PriyanthaNiroshan-3377 asked PriyanthaNiroshan-3377 commented

How to add multiple images to sqldb Image field

Dear All,
I have a SQL database call Books, containing the following fields.

ID [int]
Name varchar(50)
Author varchar(30)
Pic1 [image]
Pic2 [image]
Pic3 [image]
Active [bit]

I want to add 3 images to my SQL database using vb.NET. These images will be selected by the user via a common dialog box.

can someone help me with the sample code, please?

Thank you.
Rgds,
Niroshan.

sql-server-transact-sqldotnet-visual-basic
· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Add a dotnet-visual-basic since your question is about to VB.NET programming. Also, do not use the deprecated image data type for new SQL Server development. Use VARBINARY(MAX) Instead.

1 Vote 1 ·

Thank you!

0 Votes 0 ·

1 Answer

Viorel-1 avatar image
1 Vote"
Viorel-1 answered PriyanthaNiroshan-3377 commented

See how the @photo parameter is used to insert an image together with other details: https://docs.microsoft.com/en-us/dotnet/framework/data/adonet/sql/inserting-an-image-from-a-file. You will have three such parameters. To load the array of bytes, use File.ReadAllBytes.

The technique can be also used with UPDATE statement.


· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

thanks! Much appreciated.

0 Votes 0 ·

One issue,
vb.NET does not have such thing called

byte[] photo = GetPhoto(photoFilePath)
how to get the pic to a variable ?

0 Votes 0 ·

Got it!!!


Dim mStream As New MemoryStream()
picBox.Image.Save(mStream, System.Drawing.Imaging.ImageFormat.Jpeg)
Dim b() As Byte = mStream.ToArray()



cheers !! : )

0 Votes 0 ·