تقييم الموضوع :
  • 0 أصوات - بمعدل 0
  • 1
  • 2
  • 3
  • 4
  • 5
تغيير مكان حفظ الصورة من قاعدة البيانات إلى مجلد في مسار البرنامج
#1
الأخوة الأعزاء 

السلام عليكم ورحمة الله وبركاته ،،،

عملت مشروع بالفيجوال بيسك وهو جاهز حالياً والصور بالمشروع تحفظ في قاعدة البيانات Access ولكن قاعدة البيانات محدودة بـ 2 قيقا فقط والصور راح تاخذ هذا الحجم بسرعة

فهل يمكن تغيير كود الحفظ في قاعدة البيانات إلى الحفظ في مجلد داخل مسار البرنامج

والكود الحالي هو 

Module
كود :
Public Sub ChoosePicture(Pbox As PictureBox)
   Dim a As New OpenFileDialog
   With a
       .AddExtension = True
       .CheckPathExists = True
       .CheckFileExists = True
       .Title = "Choose Image"
       .Filter = "Choose Image (*.PNG; *.JPG; *.GIF; *.JPEG)| *.PNG; *.JPG; *.GIF; *.JPEG | All Files (*.*)|*.*"
       If .ShowDialog = DialogResult.OK Then
           Pbox.Image = Image.FromFile(.FileName)
       End If
   End With
End Sub
Public Function DGVCurrentImageView(ByVal byt As Byte()) As Image
   Dim MS As New System.IO.MemoryStream()
   Dim drwing As Image = Nothing
   MS.Write(byt, 0, byt.Length)
   drwing = New Bitmap(MS)
   MS.Close()
   Return drwing
End Function

كود الحفظ
كود :
Public Sub Insert_Car_Arshef(ByVal ID As Long, ByVal Car_Doc As PictureBox)
   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", OleDbType.Integer).Value = ID
              Dim ms As New MemoryStream()
       Dim bmpImage As New Bitmap(Car_Doc.Image)
       bmpImage.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg)
       Dim data As Byte() = ms.GetBuffer()
       Dim p As New OleDbParameter("@Car_Doc", OleDbType.Binary)
       p.Value = data
       .Parameters.Add(p)
   End With
   If con.State = 1 Then con.Close()
   con.Open()
   Cmd.ExecuteNonQuery()
   con.Close()
   MsgBox("تم إضافة السجل بنجاح", MsgBoxStyle.Information, "حفظ")
   Cmd = Nothing
End Sub

كود التعديل
كود :
Public Sub Update_Car_Arshef(ByVal Car_Doc As PictureBox, ByVal IDW As Long)
    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()
              Dim ms As New MemoryStream()
        Dim bmpImage As New Bitmap(Car_Doc.Image)
        bmpImage.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg)
        Dim data As Byte() = ms.GetBuffer()
        Dim p As New OleDbParameter("@Car_Doc", OleDbType.LongVarBinary)
        p.Value = data
        .Parameters.Add(p)
        .Parameters.AddWithValue("@ID", OleDbType.Integer).Value = IDW
    End With
    If con.State = 1 Then con.Close()
    con.Open()
    Cmd.ExecuteNonQuery()
    con.Close()
    MsgBox("تم تعديل السجل بنجاح", MsgBoxStyle.Information, "تعديل")
    Cmd = Nothing
End Sub
الرد }}}
تم الشكر بواسطة:
#2
أولا ضع المكتبات التالية :
كود :
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
الرد }}}
تم الشكر بواسطة:
#3
الله يعطيك العافية أخي أبوخالد وجزاك الله خير في الدنيا والآخرة

الحفظ شغال 100% بدون مشاكل لكن التعديل يظهر لي هذا الخطأ


الملفات المرفقة صورة/صور
   
الرد }}}
تم الشكر بواسطة: أبو خالد الشكري
#4
اللهم آمين وإياكم أجمعين

أخي F.H.M جرب كود التعديل التالي :
وإن شاء الله سيشتغل .

كود :
  Public Sub Update_Car_Arshef(ByVal Car_Doc As PictureBox, ByVal IDW As Long)

       Try
           Dim folderPath As String = Path.Combine(Application.StartupPath, "Images")

           If Not Directory.Exists(folderPath) Then
               Directory.CreateDirectory(folderPath)
           End If

           Dim imagePath As String = Path.Combine(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, "تعديل")

       Catch ex As Exception
           MsgBox("حدث خطأ أثناء محاولة تعديل الصورة" & ex.Message, MsgBoxStyle.Critical)
       End Try
   End Sub
الرد }}}
تم الشكر بواسطة:
#5
الله يحفظك أخ بوخالد

خطأ عند الضغط على زر التعديل


الملفات المرفقة صورة/صور
   
الرد }}}
تم الشكر بواسطة:
#6
سبحان الله


طيب جرب هذا الكود
كود :
Public Sub Update_Car_Arshef(ByVal Car_Doc As PictureBox, ByVal IDW As Long)

       Try
           Dim folderPath As String = Path.Combine(Application.StartupPath, "Images")

           If Not Directory.Exists(folderPath) Then
               Directory.CreateDirectory(folderPath)
           End If

           Dim imagePath As String = Path.Combine(folderPath, IDW.ToString() & ".jpg")

           If File.Exists(imagePath) Then
               File.Delete(imagePath)
           End If

           Dim bmpCopy As New Bitmap(Car_Doc.Image)
           bmpCopy.Save(imagePath, System.Drawing.Imaging.ImageFormat.Jpeg)
           bmpCopy.Dispose()

           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, "تعديل")
       Catch ex As Exception
           MsgBox("حدث خطأ أثناء محاولة تعديل الصورة" & ex.Message, MsgBoxStyle.Critical)
       End Try

   End Sub
الرد }}}
تم الشكر بواسطة:
#7
الآن يقول الخطأ بأن الصورة مستخدمة من قبل برنامج آخر


الملفات المرفقة صورة/صور
   
الرد }}}
تم الشكر بواسطة:
#8
طيب جرب هذا الكود

كود :
Public Sub Update_Car_Arshef(ByVal Car_Doc As PictureBox, ByVal IDW As Long)

       Try
           Dim folderPath As String = Path.Combine(Application.StartupPath, "Images")

           If Not Directory.Exists(folderPath) Then
               Directory.CreateDirectory(folderPath)
           End If

           Dim imagePath As String = Path.Combine(folderPath, IDW.ToString() & ".jpg")

           If File.Exists(imagePath) Then
               File.Delete(imagePath)
           End If

           Dim bmpCopy As New Bitmap(Car_Doc.Image)
           Car_Doc.Image = Nothing

           bmpCopy.Save(imagePath, System.Drawing.Imaging.ImageFormat.Jpeg)
           bmpCopy.Dispose()

           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, "تعديل")
       Catch ex As Exception
           MsgBox("حدث خطأ أثناء محاولة تعديل الصورة" & ex.Message, MsgBoxStyle.Critical)
       End Try
   End Sub
الرد }}}
تم الشكر بواسطة:
#9
أتعبتك معي بوخالد عسى الله يعطيك الصحة والعافية

نفس الرسالة السابقة الصورة مستخدمة من قبل برنامج آخر
الرد }}}
تم الشكر بواسطة:
#10
قد تكون الصورة قيد الاستخدام
جرب هذا الكود أيضا عسى يشتغل إن شاء الله
كود :
Public Sub Update_Car_Arshef(ByVal Car_Doc As PictureBox, ByVal IDW As Long)
       Try

           Dim folderPath As String = Path.Combine(Application.StartupPath, "Images")

           If Not Directory.Exists(folderPath) Then
               Directory.CreateDirectory(folderPath)
           End If

           Dim imagePath As String = Path.Combine(folderPath, IDW.ToString() & ".jpg")

           If File.Exists(imagePath) Then
               File.Delete(imagePath)
           End If

           Using bmpCopy As New Bitmap(Car_Doc.Image)
               bmpCopy.Save(imagePath, System.Drawing.Imaging.ImageFormat.Jpeg)
           End Using

           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, "تعديل")
       Catch ex As Exception
           MsgBox("حدث خطأ أثناء محاولة تعديل الصورة: " & ex.Message, MsgBoxStyle.Critical)
       End Try
   End Sub
الرد }}}
تم الشكر بواسطة:


المواضيع المحتمل أن تكون متشابهة .
الموضوع : الكاتب الردود : المشاهدات : آخر رد
  لماذا البرنامج يتوقف بدل عرض رسالة الخطأ justforit 0 98 07-12-25, 10:22 AM
آخر رد: justforit
  تصدير البيانات إلى ملف RTF مصمم هاوي 4 820 15-08-25, 04:13 PM
آخر رد: أبو خالد الشكري
  كيفية حفظ إعدادات البرنامج بحيث لا تتغير أحمد إبراهيم سعد 4 2,998 06-08-25, 06:34 PM
آخر رد: Taha Okla
  [VB.NET] ما هو أفضل موقع استضافة لقواعد البيانات MSSQL ؟ mmaalmesry 0 795 16-07-25, 10:45 PM
آخر رد: mmaalmesry
  مساعدة في كيفية ترحيل البيانات من داتا قريدفيو إلى داتا قريدفيو في فيجوال بيسك ahmedfa71 13 2,213 09-07-25, 11:24 PM
آخر رد: أبو خالد الشكري
  مشكلة في حفظ البيانات مصمم هاوي 2 1,019 30-06-25, 08:51 AM
آخر رد: مصمم هاوي
  مشكلة في جلب الصورة في التقرير مصمم هاوي 12 1,221 06-06-25, 03:00 PM
آخر رد: atefkhalf2004
  بطء في جلب البيانات مصمم هاوي 9 994 08-05-25, 07:51 AM
آخر رد: مصمم هاوي
  [VB.NET] حذف جزء من مسار ملف 1albasha 4 314 06-05-25, 04:39 PM
آخر رد: 1albasha
  [Acces2007] مشكلة ملف قاعدة بيانات access للقراءة فقط mmaalmesry 11 1,452 29-04-25, 08:55 PM
آخر رد: mmaalmesry

التنقل السريع :


يقوم بقرائة الموضوع: