28-10-24, 11:30 AM
(آخر تعديل لهذه المشاركة : 28-10-24, 11:32 AM {2} بواسطة أبو خالد الشكري.)
لحل مشكلة حذف الصورة من المجلد قم بتغيير كود Delete_Car_Arshef ليصبح كما يلي :
كود :
Public Sub Delete_Car_Arshef(ByVal dgv_Car_Arshef As DataGridView)
Dim Position As Integer = dgv_Car_Arshef.CurrentRow.Index
Dim ID_Position As Integer = dgv_Car_Arshef.Rows(Position).Cells("ID").Value
Dim imagePath As String = String.Empty
Dim getImagePathCmd As New OleDbCommand("SELECT Car_Doc FROM Car_Arshef WHERE ID = @ID", con)
getImagePathCmd.Parameters.AddWithValue("@ID", OleDbType.Integer).Value = ID_Position
If con.State = ConnectionState.Closed Then con.Open()
imagePath = getImagePathCmd.ExecuteScalar().ToString()
con.Close()
Dim deleteCmd As New OleDbCommand("DELETE FROM Car_Arshef WHERE ID = @ID", con)
deleteCmd.Parameters.AddWithValue("@ID", OleDbType.Integer).Value = ID_Position
If con.State = ConnectionState.Closed Then con.Open()
deleteCmd.ExecuteNonQuery()
con.Close()
Dim fullPath As String = Path.Combine(Application.StartupPath, imagePath)
If File.Exists(fullPath) Then
File.Delete(fullPath)
End If
MsgBox("تم حذف الصورة بنجاح.", MsgBoxStyle.Information, "حذف")
End Sub

