Solved

VB.net SQL insert images in a folder into a SQL table

Posted on 2016-09-21
3
61 Views
Last Modified: 2016-09-21
Hi

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

Thanks
0
Comment
Question by:murbro
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 

Author Comment

by:murbro
ID: 41808271
Hi. Thanks, but I was looking for VB.net code
0
 
LVL 12

Accepted Solution

by:
Máté Farkas earned 500 total points
ID: 41808427
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)

Reader.Close()
Stream.Close()

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

Open in new window

0
 

Author Closing Comment

by:murbro
ID: 41808432
thanks very much
0

Featured Post

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
I have a large data set and a SSIS package. How can I load this file in multi threading?
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Via a live example, show how to shrink a transaction log file down to a reasonable size.

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question