Can i store a image in a DB without just saving it's location??? ie. if I have just a .mdb and I want to access this or send this file via email can someone view a photo?? if so how?
This is my code plus my error... what is wrong the DB has number field with a byte size...
Code:
Try
OpenFileDialog1.Filter = "Image Files (*.jpg)|*.jpg"
OpenFileDialog1.ShowDialog()
PictureBox1.ImageLocation = OpenFileDialog1.FileName
Dim connection As New Data.OleDb.OleDbConnection(My.Settings.Database1ConnectionString)
Dim sqlqry As New OleDb.OleDbCommand("UPDATE Contacts SET Picture = @Picture WHERE ID = " & TextBox8.Text, connection)
Using picture As Image = Image.FromFile(PictureBox1.ImageLocation)
Using stream As New IO.MemoryStream
picture.Save(stream, Imaging.ImageFormat.Jpeg)
sqlqry.Parameters.Add("@Picture", OleDb.OleDbType.VarBinary).Value = stream.GetBuffer()
'SqlDbType.Image).Value = stream.GetBuffer()
End Using
End Using
connection.Open()
sqlqry.ExecuteNonQuery()
connection.Close()
Catch ex As Exception
MessageBox.Show(ex.ToString)
End Try
yeah thanks for the reply, I just got it working with that a moment ago, so to delete a picture how do you update with no object?
I mean this will not work but what does one do?
Code:
Try
Dim connection As New Data.OleDb.OleDbConnection(My.Settings.Database1ConnectionString)
Dim sqlqry As New OleDb.OleDbCommand("UPDATE Contacts SET Picture = "" WHERE ContactID = " & TextBox8.Text, connection)
connection.Open()
sqlqry.ExecuteNonQuery()
connection.Close()
Catch ex As Exception
MessageBox.Show(ex.ToString)
End Try
To set any database field to null from VB code you assign DBNull.Value to the field or parameter. That means you'd use exactly the same SQL code as before but you'd assign DBNull.Value to the paarmeter instead of a Byte array.