0

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.

2
  • normally only image names are stored on the db. The image is stored on the server Commented Oct 31, 2013 at 11:54
  • Try something first and then show us what you have tried. And from there the SO community will provide you with suggestions and/or solutions. Commented Oct 31, 2013 at 12:04

2 Answers 2

0

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.

http://social.msdn.microsoft.com/Forums/vstudio/en-US/d9068625-ec19-44c9-9650-816e6f12af72/vb-net-codessaving-image-direct-to-sql-table?forum=vbgeneral

Sign up to request clarification or add additional context in comments.

2 Comments

sir, what i wanted was how do i do this using VB2012 as a front end?
Have you looked at this? : stackoverflow.com/questions/16409419/…
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.