مشكلة في عرض وتخزين الصور في الاكسس بمسار للصورة - khaled12345 - 16-04-17
السلام عليكم ورحمة الله وبركاته
عملت مشروع بسيط لعرض وتخزين الصور عن طريق مسار الصورة وحفظها في الاكسس
الصورة فعلا تخزن في ملف الصور داخل البرنامج ولكن لا تعرض ولا تدخل في ملف الاكسس
برجاء المساعدة والملف في المرفقات
مع فائق الشكر والاحترام
RE: مشكلة في عرض وتخزين الصور في الاكسس بمسار للصورة - عبـدالله - 16-04-17
تفضل التعديل
PHP كود :
Imports System.Data.OleDb ' استدعاء مكتبة الفيجوال بيسك Imports System.IO
Public Class Form1
'كود جملة استدعاء الاكسس Public cn As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0; " & " Data Source = " & Application.StartupPath & "\Data.accdb")
Dim dt As New DataTable
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Loaddt() End Sub
Private Sub Loaddt() dt.Clear() Dim da As New OleDbDataAdapter("SELECT * FROM [Table1]", cn) da.Fill(dt) DataGridView1.DataSource = dt End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click OpenFileDialog1.Filter = "imge|*.img;*.bmp;*.png;*.jpg" If OpenFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then Dim PicName As String = System.IO.Path.GetFileName(OpenFileDialog1.FileName) Dim Picimge As String = OpenFileDialog1.FileName Savedt(PicName, Picimge) End If End Sub
Private Sub Savedt(name1 As String, imge As String) Dim cm As New OleDbCommand("INSERT INTO [Table1] ([Name1], [imge]) VALUES (@name1, @imge)", cn) cm.Parameters.AddWithValue("@name1", name1) cm.Parameters.AddWithValue("@imge", imge) If cn.State <> ConnectionState.Open Then cn.Open() cm.ExecuteNonQuery() cn.Close() Loaddt() MsgBox("تم حفظ الصورة") End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click If BindingContext(dt).Position <> -1 Then Dim Position As Integer = Me.BindingContext(dt).Position PictureBox1.Load(dt.Rows(Position).Item("imge")) PictureBox1.SizeMode = PictureBoxSizeMode.Zoom End If End Sub
End Class
RE: مشكلة في عرض وتخزين الصور في الاكسس بمسار للصورة - khaled12345 - 16-04-17
(16-04-17, 07:42 AM)عبـدالله كتب : تفضل التعديل
الف الف الف شكر الاخ الحبيب عبد الله
جزاك الله كل الخير
PHP كود :
Imports System.Data.OleDb ' استدعاء مكتبة الفيجوال بيسك Imports System.IO
Public Class Form1
'كود جملة استدعاء الاكسس Public cn As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0; " & " Data Source = " & Application.StartupPath & "\Data.accdb")
Dim dt As New DataTable
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Loaddt() End Sub
Private Sub Loaddt() dt.Clear() Dim da As New OleDbDataAdapter("SELECT * FROM [Table1]", cn) da.Fill(dt) DataGridView1.DataSource = dt End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click OpenFileDialog1.Filter = "imge|*.img;*.bmp;*.png;*.jpg" If OpenFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then Dim PicName As String = System.IO.Path.GetFileName(OpenFileDialog1.FileName) Dim Picimge As String = OpenFileDialog1.FileName Savedt(PicName, Picimge) End If End Sub
Private Sub Savedt(name1 As String, imge As String) Dim cm As New OleDbCommand("INSERT INTO [Table1] ([Name1], [imge]) VALUES (@name1, @imge)", cn) cm.Parameters.AddWithValue("@name1", name1) cm.Parameters.AddWithValue("@imge", imge) If cn.State <> ConnectionState.Open Then cn.Open() cm.ExecuteNonQuery() cn.Close() Loaddt() MsgBox("تم حفظ الصورة") End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click If BindingContext(dt).Position <> -1 Then Dim Position As Integer = Me.BindingContext(dt).Position PictureBox1.Load(dt.Rows(Position).Item("imge")) PictureBox1.SizeMode = PictureBoxSizeMode.Zoom End If End Sub
End Class
RE: مشكلة في عرض وتخزين الصور في الاكسس بمسار للصورة - عبـدالله - 16-04-17
هذا تعديل أفضل مع إضافة حفظ الصورة في مجلد الصور الخاص بالبرنامج مع عدم حفظ الصورة أكثر من مرة
مع تعديل بعض خصائص DataGridView لوضع تعامل أفضل
PHP كود :
Imports System.Data.OleDb ' استدعاء مكتبة الفيجوال بيسك Imports System.IO
Public Class Form1
Dim myImageFolder As String = Application.StartupPath & "\Pic\"
'كود جملة استدعاء الاكسس Public cn As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0; " & " Data Source = " & Application.StartupPath & "\Data.accdb")
Dim dt As New DataTable
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.DataGridView1.AllowUserToAddRows = False Me.DataGridView1.AllowUserToDeleteRows = False Me.DataGridView1.ReadOnly = True Me.DataGridView1.MultiSelect = False Me.DataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect Me.DataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells
Loaddt()
End Sub
Private Sub Loaddt() dt.Clear() Dim da As New OleDbDataAdapter("SELECT * FROM [Table1]", cn) da.Fill(dt) DataGridView1.DataSource = dt End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click OpenFileDialog1.Filter = "imge|*.img;*.bmp;*.png;*.jpg" If OpenFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
Dim PicName As String = System.IO.Path.GetFileNameWithoutExtension(OpenFileDialog1.FileName) Dim Picimge As String = System.IO.Path.GetFileName(OpenFileDialog1.FileName)
If IO.File.Exists(myImageFolder & Picimge) Then MsgBox("الصورة موجود سابقاً")
Else My.Computer.FileSystem.CopyFile(OpenFileDialog1.FileName, myImageFolder & Picimge) Savedt(PicName, Picimge)
End If
End If End Sub
Private Sub Savedt(name1 As String, imge As String) Dim cm As New OleDbCommand("INSERT INTO [Table1] ([Name1], [imge]) VALUES (@name1, @imge)", cn) cm.Parameters.AddWithValue("@name1", name1) cm.Parameters.AddWithValue("@imge", imge) If cn.State <> ConnectionState.Open Then cn.Open() cm.ExecuteNonQuery() cn.Close() Loaddt() MsgBox("تم حفظ الصورة") End Sub
Private Sub DataGridView1_SelectionChanged(sender As Object, e As System.EventArgs) Handles DataGridView1.SelectionChanged If BindingContext(dt).Position <> -1 Then Dim Position As Integer = Me.BindingContext(dt).Position PictureBox1.Load(myImageFolder & dt.Rows(Position).Item("imge")) PictureBox1.SizeMode = PictureBoxSizeMode.Zoom End If End Sub
End Class
RE: مشكلة في عرض وتخزين الصور في الاكسس بمسار للصورة - khaled12345 - 16-04-17
(16-04-17, 09:01 AM)عبـدالله كتب : هذا تعديل أفضل مع إضافة حفظ الصورة في مجلد الصور الخاص بالبرنامج مع عدم حفظ الصورة أكثر من مرة
مع تعديل بعض خصائص DataGridView لوضع تعامل أفضل
==========================================
ما شاء الله ولا قوة الا باالله
ربنا يبارك فيك الاخ الحبيب عبد الله
وفيت وما قصرت اخي الكريم
PHP كود :
Imports System.Data.OleDb ' استدعاء مكتبة الفيجوال بيسك Imports System.IO
Public Class Form1
Dim myImageFolder As String = Application.StartupPath & "\Pic\"
'كود جملة استدعاء الاكسس Public cn As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0; " & " Data Source = " & Application.StartupPath & "\Data.accdb")
Dim dt As New DataTable
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.DataGridView1.AllowUserToAddRows = False Me.DataGridView1.AllowUserToDeleteRows = False Me.DataGridView1.ReadOnly = True Me.DataGridView1.MultiSelect = False Me.DataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect Me.DataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells
Loaddt()
End Sub
Private Sub Loaddt() dt.Clear() Dim da As New OleDbDataAdapter("SELECT * FROM [Table1]", cn) da.Fill(dt) DataGridView1.DataSource = dt End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click OpenFileDialog1.Filter = "imge|*.img;*.bmp;*.png;*.jpg" If OpenFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
Dim PicName As String = System.IO.Path.GetFileNameWithoutExtension(OpenFileDialog1.FileName) Dim Picimge As String = System.IO.Path.GetFileName(OpenFileDialog1.FileName)
If IO.File.Exists(myImageFolder & Picimge) Then MsgBox("الصورة موجود سابقاً")
Else My.Computer.FileSystem.CopyFile(OpenFileDialog1.FileName, myImageFolder & Picimge) Savedt(PicName, Picimge)
End If
End If End Sub
Private Sub Savedt(name1 As String, imge As String) Dim cm As New OleDbCommand("INSERT INTO [Table1] ([Name1], [imge]) VALUES (@name1, @imge)", cn) cm.Parameters.AddWithValue("@name1", name1) cm.Parameters.AddWithValue("@imge", imge) If cn.State <> ConnectionState.Open Then cn.Open() cm.ExecuteNonQuery() cn.Close() Loaddt() MsgBox("تم حفظ الصورة") End Sub
Private Sub DataGridView1_SelectionChanged(sender As Object, e As System.EventArgs) Handles DataGridView1.SelectionChanged If BindingContext(dt).Position <> -1 Then Dim Position As Integer = Me.BindingContext(dt).Position PictureBox1.Load(myImageFolder & dt.Rows(Position).Item("imge")) PictureBox1.SizeMode = PictureBoxSizeMode.Zoom End If End Sub
End Class
|