First of all, I'd like to point out that I'm very new to programming and still learning.
I'm trying to insert multiple images into my table with a click of a button. I have my images stored in a folder and the file names of these images match with ID column in my SQL Server table.
My table has 30 columns and 5000 rows. I'm able to connect my table but I just don't know how to insert all images in this folder to my table with matching ID (i.e if ID=123456 I want to insert an image file named 123456.jpg to the column Photo
).
Below is my code and any help would be appreciated. By the way, column Photo
is of datatype varbinary(max)
.
Dim con As SqlConnection
Dim cmd As SqlCommand
Dim ds As New DataSet
con = New SqlConnection("server=MY-PC; Initial Catalog=Northwind;Integrated Security=SSPI")
cmd = New SqlCommand()
con.Open()
cmd.Connection = con
BindingSource1.DataSource =
cmd.CommandText = "SELECT * FROM Northwind WHERE ID LIKE '" + TextBox1.Text + "'"
' dr = cmd.ExecuteReader
Dim adapter As New SqlDataAdapter(cmd)
Dim table As New DataTable
adapter.Fill(table)
BindingSource1.DataSource = table
DataGridView1.DataSource = BindingSource1
I tried:
Dim BS As New BindingSource 'assumes this is bound to your table already
PictureBox1.DataBindings.Add("Image", BS, "ImageCol")
For Each DrowView As DataRowView In BS
PictureBox1.Image = Image.FromFile("PathToImages\" & DrowView("NameID") & ".jpg")
Try
Using SqlConn As New SqlConnection("server=MY-PC; Initial Catalog=Northwind;Integrated Security=SSPI")
Using NorthwindDA As New SqlDataAdapter("SELECT * FROM Northwind Where ID like '" + TextBox1.Text + "'", SqlConn)
Using NorthwindCB As New SqlCommandBuilder(NorthwindDA)
NorthwindDA.Update(table)
End Using
End Using
End Using
Catch ex As Exception
'Handle exception
End Try
Next
I'm getting an error
Cannot bind to the property or column Image on the DataSource. Parameter name: dataMember