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


1- عندي قاعدة بيانات اكسيس واستخدم فيجول بيسك دوت نت بالاتصال المنفصل


    - عملت 2 عمود بقاعدة البيانات OLE Object

    - احدهما لحفظ الصور والاخر لحفظ صفحات الويب و ملفات pdf

      بحفظ الصور وبعرضها عادي جدا ولكن المشكلة في حفظ ملفات pdf وصفحات النت بقاعدة البيانات وعرضها بالفورم

        كود اسناد الصورة لقاعدة البيانات

             PictureBox1.DataBindings.Add("Image", BindingSource1, "pic_prod", True)


انا حاولت بطريقة حفظ كل ملفات الصفح بفولدر وحفظ مسارتها بقاعدة البيانات وعند الضغط علي قاعدة البيانات يحدد الصفح وملفات البي دي اف بالطريقة دية

كود :
Process.Start
DataGridView1.SelectedRows.Item(0).Cells(1).Value

بس طريقة فاشلة جدا

كود الحفظ بقاعدة البيانات للمدخلات 

كود :
 BindingSource1.EndEdit()
           DataAdapter1.Update(DataSet1, "Tb1")
الرد }}}
تم الشكر بواسطة:
#2
كود :
'First save the image to the table
   Private Function SaveImageToDB(ByRef name As String) As Boolean
       Try
           Dim conn As New OleDbConnection
           Dim cmd As OleDbCommand

           conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Database1.mdb;PERSIST SECURITY INFO = false"
           conn.Open()

           cmd = conn.CreateCommand()
           cmd.CommandText = "INSERT INTO Table1(Name, Image) VALUES (@Name, @Image)"
           Dim imgByteArray() As Byte
           Try
               Dim stream As New MemoryStream
               Dim bmp As New Bitmap(stream)

               bmp.Save(stream, ImageFormat.Jpeg)
               imgByteArray = stream.ToArray()
               stream.Close()

               cmd.Parameters.AddWithValue("@Name", name)
               cmd.Parameters.AddWithValue("@Image", imgByteArray)

               If DirectCast(cmd.ExecuteNonQuery(), Integer) > 0 Then
                   Return True
               End If
           Catch ex As Exception
               MessageBox.Show(ex.Message)
               Return False
           End Try

           conn.Close()
           cmd.Dispose()
           conn.Dispose()
       Catch ex As Exception
           MessageBox.Show(ex.Message)
           Return False
       End Try
   End Function

   'Retrieve image from table
   Public Function GetImageFromDB(ByRef imageName As String) As Bitmap
       Try
           Dim conn As New OleDbConnection
           Dim cmd As OleDbCommand
           Dim reader As OleDbDataReader

           conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Database1.mdb;PERSIST SECURITY INFO = false"
           conn.Open()

           cmd = conn.CreateCommand()
           cmd.CommandText = "SELECT Image FROM ImageTable WHERE ImageName = '" & imageName & "'"

           reader = cmd.ExecuteReader

           If reader.Read Then
               Dim imgByteArray() As Byte

               Try
                   imgByteArray = CType(reader(0), Byte())
                   Dim stream As New MemoryStream(imgByteArray)
                   Dim bmp As New Bitmap(stream)
                   stream.Close()
                   Return bmp
               Catch ex As Exception
                   MessageBox.Show(ex.Message)
                   Return Nothing
               End Try
           End If

           reader.Close()
           conn.Close()

           cmd.Dispose()
           conn.Dispose()
       Catch ex As Exception
           MessageBox.Show(ex.Message)
           Return Nothing
       End Try
   End Function
الرد }}}
تم الشكر بواسطة: العيدروس
#3
(09-11-17, 08:48 PM)Rabeea Qbaha كتب :
كود :
'First save the image to the table
   Private Function SaveImageToDB(ByRef name As String) As Boolean
       Try
           Dim conn As New OleDbConnection
           Dim cmd As OleDbCommand

           conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Database1.mdb;PERSIST SECURITY INFO = false"
           conn.Open()

           cmd = conn.CreateCommand()
           cmd.CommandText = "INSERT INTO Table1(Name, Image) VALUES (@Name, @Image)"
           Dim imgByteArray() As Byte
           Try
               Dim stream As New MemoryStream
               Dim bmp As New Bitmap(stream)

               bmp.Save(stream, ImageFormat.Jpeg)
               imgByteArray = stream.ToArray()
               stream.Close()

               cmd.Parameters.AddWithValue("@Name", name)
               cmd.Parameters.AddWithValue("@Image", imgByteArray)

               If DirectCast(cmd.ExecuteNonQuery(), Integer) > 0 Then
                   Return True
               End If
           Catch ex As Exception
               MessageBox.Show(ex.Message)
               Return False
           End Try

           conn.Close()
           cmd.Dispose()
           conn.Dispose()
       Catch ex As Exception
           MessageBox.Show(ex.Message)
           Return False
       End Try
   End Function

   'Retrieve image from table
   Public Function GetImageFromDB(ByRef imageName As String) As Bitmap
       Try
           Dim conn As New OleDbConnection
           Dim cmd As OleDbCommand
           Dim reader As OleDbDataReader

           conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Database1.mdb;PERSIST SECURITY INFO = false"
           conn.Open()

           cmd = conn.CreateCommand()
           cmd.CommandText = "SELECT Image FROM ImageTable WHERE ImageName = '" & imageName & "'"

           reader = cmd.ExecuteReader

           If reader.Read Then
               Dim imgByteArray() As Byte

               Try
                   imgByteArray = CType(reader(0), Byte())
                   Dim stream As New MemoryStream(imgByteArray)
                   Dim bmp As New Bitmap(stream)
                   stream.Close()
                   Return bmp
               Catch ex As Exception
                   MessageBox.Show(ex.Message)
                   Return Nothing
               End Try
           End If

           reader.Close()
           conn.Close()

           cmd.Dispose()
           conn.Dispose()
       Catch ex As Exception
           MessageBox.Show(ex.Message)
           Return Nothing
       End Try
   End Function


اريد حفظ ملفات البي دي اف وليس الصور انا بحفظ الصور وباستعرضها

وكود الاتصال لدي

Public con As New OleDb.OleDbConnection("provider=microsoft.ace.oledb.12.0;data source=" & Application.StartupPath & "\product.accdb")
الرد }}}
تم الشكر بواسطة:
#4
http://vb4arb.com/vb/showthread.php?tid=16992
http://vb4arb.com/vb/showthread.php?tid=17876
اللهم يا ارحم الراحمين ارحم اخي اباليث رحمة واسعة
 
الرد }}}
تم الشكر بواسطة:
#5
(09-11-17, 08:59 PM)محمد اسماعيل كتب :
(09-11-17, 08:48 PM)Rabeea Qbaha كتب :
كود :
'First save the image to the table
   Private Function SaveImageToDB(ByRef name As String) As Boolean
       Try
           Dim conn As New OleDbConnection
           Dim cmd As OleDbCommand

           conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Database1.mdb;PERSIST SECURITY INFO = false"
           conn.Open()

           cmd = conn.CreateCommand()
           cmd.CommandText = "INSERT INTO Table1(Name, Image) VALUES (@Name, @Image)"
           Dim imgByteArray() As Byte
           Try
               Dim stream As New MemoryStream
               Dim bmp As New Bitmap(stream)

               bmp.Save(stream, ImageFormat.Jpeg)
               imgByteArray = stream.ToArray()
               stream.Close()

               cmd.Parameters.AddWithValue("@Name", name)
               cmd.Parameters.AddWithValue("@Image", imgByteArray)

               If DirectCast(cmd.ExecuteNonQuery(), Integer) > 0 Then
                   Return True
               End If
           Catch ex As Exception
               MessageBox.Show(ex.Message)
               Return False
           End Try

           conn.Close()
           cmd.Dispose()
           conn.Dispose()
       Catch ex As Exception
           MessageBox.Show(ex.Message)
           Return False
       End Try
   End Function

   'Retrieve image from table
   Public Function GetImageFromDB(ByRef imageName As String) As Bitmap
       Try
           Dim conn As New OleDbConnection
           Dim cmd As OleDbCommand
           Dim reader As OleDbDataReader

           conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Database1.mdb;PERSIST SECURITY INFO = false"
           conn.Open()

           cmd = conn.CreateCommand()
           cmd.CommandText = "SELECT Image FROM ImageTable WHERE ImageName = '" & imageName & "'"

           reader = cmd.ExecuteReader

           If reader.Read Then
               Dim imgByteArray() As Byte

               Try
                   imgByteArray = CType(reader(0), Byte())
                   Dim stream As New MemoryStream(imgByteArray)
                   Dim bmp As New Bitmap(stream)
                   stream.Close()
                   Return bmp
               Catch ex As Exception
                   MessageBox.Show(ex.Message)
                   Return Nothing
               End Try
           End If

           reader.Close()
           conn.Close()

           cmd.Dispose()
           conn.Dispose()
       Catch ex As Exception
           MessageBox.Show(ex.Message)
           Return Nothing
       End Try
   End Function


اريد حفظ ملفات البي دي اف وليس الصور انا بحفظ الصور وباستعرضها

وكود الاتصال لدي

Public con As New OleDb.OleDbConnection("provider=microsoft.ace.oledb.12.0;data source=" & Application.StartupPath & "\product.accdb")

طريقه حفظ ملفات pdf نفس حفظ الصور لانه بالحالتين يقوم بتحويلهم الى bit وبد ذالك يخزنو في قاعده البيانات
الرد }}}
تم الشكر بواسطة:
#6
اعتزر لك اخي جميل علي

لا استخدم هذة الطريقة لتعامل مع قاعدة البيانات ولم اقد ر علي استخلاص ما احتاج ببرنامجي

انا بستخدم الطريقة دية لحفظ الصور ومسحها ووضعت امتداد لكل الملفات ولكن لاتحفظ بقاعدة البيانات وتحفظ الصور فقط وذالك لان الكود يصف الصور كاملا ليست اكواد حفظ الصور متشابة مع اكواد حفظ html ,pdf ,doc

Private Sub savimage_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles savimage.Click
' save
If BindingSource1.Count = 0 Then Beep() : Exit Sub


Try
If PictureBox1.Image IsNot Nothing Then

If MsgBox(" هل تريد استبدال الصورة الحالية " & " ؟ ", MsgBoxStyle.Exclamation + MsgBoxStyle.MsgBoxRight + MsgBoxStyle.OkCancel, "استبدال صورة") = MsgBoxResult.Cancel Then Exit Sub
Else

If MsgBox(" استمرار اضافة صورة جديدة للسجل رقم " & Label2.Text & " ؟ ", MsgBoxStyle.Exclamation + MsgBoxStyle.MsgBoxRight + MsgBoxStyle.OkCancel, "ادراج صورة") = MsgBoxResult.Cancel Then Exit Sub

End If


Application.DoEvents()



Dim OFG As New OpenFileDialog

OFG.Filter = "Image Files (*.bmp;*.jpg;*.jpeg;*.GIF)|*.bmp;*.jpg;*.jpeg;*.GIF|" + _
"PNG files (*.png)|*.png|text files (*.text)|*.txt|doc files (*.doc)|*.doc|pdf files (*.pdf)|*.pdf" '"Files(*.jpg)|*.jpg|Files(*.gif)|*.gif|Files(*.bmp)|*.bmp|Files(*.png)|*.png"

OFG.Title = "ادراج صورة"
OFG.FileName = ""


If OFG.ShowDialog() = Windows.Forms.DialogResult.OK Then

Dim fs As IO.FileStream = New IO.FileStream(OFG.FileName, IO.FileMode.Open, IO.FileAccess.Read)
Dim LoadImage As Image = Image.FromStream(fs)
fs.Close()

Dim Stream As New IO.MemoryStream()
Dim NewBitmap As New Bitmap(LoadImage, 200, 225)
NewBitmap.Save(Stream, System.Drawing.Imaging.ImageFormat.Jpeg)
Application.DoEvents()
BindingSource1.EndEdit()
DataAdapter1.Update(DataSet1.Tables("purch_tb"))
DataSet1.Tables("purch_tb").Rows(BindingSource1.Position).Item("pic_prod") = Stream.ToArray
Stream.Close()
BindingSource1.EndEdit()
DataAdapter1.Update(DataSet1.Tables("purch_tb"))
Application.DoEvents()
MsgBox("تم حفظ الصورة نجاح", MsgBoxStyle.MsgBoxRight + MsgBoxStyle.Information, "نجاح ")
End If
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)

End Try


End Sub

Private Sub deletimage_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles deletimage.Click
Try

If PictureBox1.Image Is Nothing Then Beep() : MsgBox("لايوجد صورة ليتم حذفها") : Exit Sub

If MsgBox(" استمرار حذف الصورة الحالية" & " ؟ ", MsgBoxStyle.Exclamation + MsgBoxStyle.MsgBoxRight + MsgBoxStyle.OkCancel, "حذف صورة") = MsgBoxResult.Cancel Then Exit Sub

PictureBox1.Image = Nothing

BindingSource1.EndEdit()
DataAdapter1.Update(DataSet1.Tables("purch_tb"))


MsgBox("تم حذف الصورة نجاح", MsgBoxStyle.MsgBoxRight + MsgBoxStyle.Information, "نجاح ")


Catch ex As Exception

MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)

End Try

End Sub
الرد }}}
تم الشكر بواسطة:


المواضيع المحتمل أن تكون متشابهة .
الموضوع : الكاتب الردود : المشاهدات : آخر رد
  مشكلة فى جمع عمود فى داتا جريد فيو احمد خطاب 3 168 06-03-24, 07:49 PM
آخر رد: احمد خطاب
  حذف الاسطر الفارغه من الداتا جريد فيو اليوم السابع 3 2,383 03-03-24, 12:57 AM
آخر رد: مصمم هاوي
  كيفية جمع أرقام عمود فى الداتا جريد فيو بناءاً على بيانات معينة heem1986 5 241 25-02-24, 11:26 PM
آخر رد: heem1986
  [C#.NET] طباعة بيانات داتا جرد فيو h2551996 0 95 25-02-24, 02:31 PM
آخر رد: h2551996
  كيفية تنفيذ امر عند التعليم على checkbox بالداتا جريد فيو heem1986 2 164 21-02-24, 01:37 AM
آخر رد: heem1986
  [VB.NET] ستايل داتا جرد فيو h2551996 10 355 17-01-24, 02:52 PM
آخر رد: aljzazy
Heart [C#.NET] حول بطئ عملية نقل البينات الكثيرة من أكسس إلى داتا غريد فيو بلال بلال 11 724 15-12-23, 07:47 AM
آخر رد: foad8920
  انتقال المؤشر بين الخلايا في نفس الصف في الداتا جريد فيو fares_mohammed 2 472 03-11-23, 09:57 PM
آخر رد: fares_mohammed
  يوجد مشكلة عند تحميل البيانات فى كمبوبوكس داخل داتا جريد new_programer 2 477 17-10-23, 06:51 PM
آخر رد: new_programer
  [VB.NET] مشكلة في داتا جرد فيو h2551996 4 461 13-09-23, 01:26 PM
آخر رد: h2551996

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


يقوم بقرائة الموضوع: بالاضافة الى ( 1 ) ضيف كريم