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

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
Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAsked:
Who is Participating?
 
Máté FarkasConnect With a Mentor Database 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)

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
 
Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAuthor Commented:
Hi. Thanks, but I was looking for VB.net code
0
 
Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAuthor Commented:
thanks very much
0
All Courses

From novice to tech pro — start learning today.