Improve company productivity with a Business Account.Sign Up

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 85
  • Last Modified: SQL insert images in a folder into a SQL table


I have a folder on my desktop called "MyPics". I have a SQL table called Pics with three columns: ID, Pic, Detail.
What code would I use to insert all the pics in my folder into the SQL table in my Windows Forms application?

Murray Brown
Murray Brown
  • 2
1 Solution
Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAuthor Commented:
Hi. Thanks, but I was looking for code
Máté FarkasDatabase Developer and AdministratorCommented:
Dim Conn As SqlConnection = New SqlConnection("<connection_string_to_sql_database>")
Dim Comm As SqlCommand = New SqlCommand("INSERT INTO Pics(Pic) Values(@Pic)", Conn)
Dim Stream As FileStream = New FileStream("<full_path_to_file>", FileMode.Open, FileAccess.Read)
Dim Reader As BinaryReader = New BinaryReader(Stream)
Dim Photo() As Byte = Reader.ReadBytes(Stream.Length)


Comm.Parameters.Add("@Pic",  SqlDbType.Image, Photo.Length).Value = Photo

Open in new window

Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAuthor Commented:
thanks very much
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

A proven path to a career in data science

At Springboard, we know how to get you a job in data science. With Springboard’s Data Science Career Track, you’ll master data science  with a curriculum built by industry experts. You’ll work on real projects, and get 1-on-1 mentorship from a data scientist.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now