27-10-24, 09:22 AM
أولا ضع المكتبات التالية :
الآن قم باستبدال الأكواد السابقة إلى الأكواد التالية :
كود :
Imports System.IO
Imports System.Data.OleDb
Imports System.Drawing
Imports System.Windows.Formsالآن قم باستبدال الأكواد السابقة إلى الأكواد التالية :
كود :
Public Sub Insert_Car_Arshef(ByVal ID As Long, ByVal Car_Doc As PictureBox)
Dim folderPath As String = Application.StartupPath & "\Images\"
If Not Directory.Exists(folderPath) Then
Directory.CreateDirectory(folderPath)
End If
Dim imagePath As String = folderPath & ID.ToString() & ".jpg"
Car_Doc.Image.Save(imagePath, System.Drawing.Imaging.ImageFormat.Jpeg)
Dim Cmd As New OleDbCommand
With Cmd
.Connection = con
.CommandType = CommandType.Text
.CommandText = "Insert Into Car_Arshef (ID, Car_Doc) values(@ID, @Car_Doc)"
.Parameters.Clear()
.Parameters.AddWithValue("@ID", ID)
.Parameters.AddWithValue("@Car_Doc", imagePath)
End With
If con.State = ConnectionState.Open Then con.Close()
con.Open()
Cmd.ExecuteNonQuery()
con.Close()
MsgBox("تم إضافة السجل بنجاح", MsgBoxStyle.Information, "حفظ")
End Subكود :
Public Sub Update_Car_Arshef(ByVal Car_Doc As PictureBox, ByVal IDW As Long)
Dim folderPath As String = Application.StartupPath & "\Images\"
If Not Directory.Exists(folderPath) Then
Directory.CreateDirectory(folderPath)
End If
Dim imagePath As String = folderPath & IDW.ToString() & ".jpg"
Car_Doc.Image.Save(imagePath, System.Drawing.Imaging.ImageFormat.Jpeg)
Dim Cmd As New OleDbCommand
With Cmd
.Connection = con
.CommandType = CommandType.Text
.CommandText = "Update Car_Arshef Set Car_Doc = @Car_Doc Where ID = @ID"
.Parameters.Clear()
.Parameters.AddWithValue("@Car_Doc", imagePath)
.Parameters.AddWithValue("@ID", IDW)
End With
If con.State = ConnectionState.Open Then con.Close()
con.Open()
Cmd.ExecuteNonQuery()
con.Close()
MsgBox("تم تعديل السجل بنجاح", MsgBoxStyle.Information, "تعديل")
End Subكود :
Public Function DGVCurrentImageView(ByVal imagePath As String) As Image
If File.Exists(imagePath) Then
Return Image.FromFile(imagePath)
Else
Return Nothing
End If
End Function


