How can I insert an image from my computer into SQL using VB 2012?
Consider that the image name is XYZ, located in "My Documents". the image is to be inserted into a field named ABC.
How can I insert an image from my computer into SQL using VB 2012?
Consider that the image name is XYZ, located in "My Documents". the image is to be inserted into a field named ABC.
You need to have a binary field for that. I found this on the internet.
CREATE TABLE Images(image varbinary(max))
INSERT INTO Images(image)
SELECT * FROM
OPENROWSET(BULK N'C:\My Documents\Image1.jpg', SINGLE_BLOB)
Give this a try, or change it to fit your tables. Notice that the C:\ is the disk of the sql server.
This is however the SQL CODE not in VB. But you can simply put this statement into a New SqlCommand
I found the code here: http://forums.asp.net/t/1867959.aspx
EDIT
This article here shows a example of how it can be done in vb.
You need to create a binary column in the table first, as has been suggested by Kay Nelson, however I imagine the file to store is not on the server, so to store it in the table, you need to open a filestream and write it to the server. Have a look at How to save a PDF file in a SQL Server column using vb.net code - it's in C# but it's very easy to translate to VB.NET.