อันนี้เป็นโค้ด เพิ่มเติม ค่ะ(ใครปุ่มเดียวกัน)
cmd = New OleDbCommand(sql, con)
cmd.Parameters.AddWithValue("idn", IdNumbertxt.Text)
cmd.Parameters.AddWithValue("edate", Datetxt.Text)
cmd.Parameters.AddWithValue("eposition", Positiontxt.Text)
cmd.Parameters.AddWithValue("estatus", StatusBox.Text)
cmd.Parameters.AddWithValue("efrontname", FrontNametxt.Text)
cmd.Parameters.AddWithValue("elastname", LastNametxt.Text)
cmd.Parameters.AddWithValue("edateregister", DateRegistertxt.Text)
Dim fiStream As New FileStream(OpenFileDialog1.FileName, _
FileMode.Open, _
FileAccess.Read)
Dim binReader As New BinaryReader(fiStream)
Dim pic() As Byte = binReader.ReadBytes(fiStream.Length)
cmd.Parameters.AddWithValue("pic", pic)
Dim affect As Integer = cmd.ExecuteNonQuery()
If (affect < 1) Then
MsgBox("เกิดข้อผิดพลาด" & vbNewLine & "ไม่สามารถเพิ่มข้อมูลได้")
Else
MsgBox("เพิ่มข้อมูลเรียบร้อยแล้ว")
End If
End If
อันนี้เป็นปุ่มนำรูปภาพมาใส่ค่ะ
Private Sub Picturebtt_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Picturebtt.Click
With OpenFileDialog1
.Filter = "Image Files(*.gif;*.jpg) | *.gif;*.jpg"
.FileName = ""
If (.ShowDialog() = DialogResult.OK) Then
Picturetxt.Text = .FileName
PictureBox1.Image = Image.FromFile(.FileName)
End If
End With
End Sub
Database ของผมเป็น MS SQL Server เอารูปจาก Picturebox ลงไปเซฟ Code (VB.NET)
Dim ms As MemoryStream = New MemoryStream
Dim filetype As System.Drawing.Imaging.ImageFormat
filetype = picbox.Image.RawFormat
picbox.Image.Save(ms, filetype)
Dim bytBLOBData(CInt(ms.Length() - 1)) As Byte
ms.Position = 0
ms.Read(bytBLOBData, 0, bytBLOBData.Length)
ms.Close()
Dim file As New SqlParameter("@FileName", SqlDbType.VarBinary, bytBLOBData.Length, ParameterDirection.Input, False, 0, 0, Nothing, DataRowVersion.Current, bytBLOBData)
.Add(file)