تقييم الموضوع :
  • 0 أصوات - بمعدل 0
  • 1
  • 2
  • 3
  • 4
  • 5
لايتم الحفظ ولاتنعرض الصورة ارجو المساعدة
#1
السلام عليكم....
في البداية احب اشكركم على هالمنتدى الجميل
عندي مشكلة انا عاملة فورم ورابطة بقاعدة بيانات
ومن ضمن الحقول الموجودة في الفورم حقل لرابط الصورة
المهم انني لااستطيع الاضافة والحفظ وكذلك لاتظهر صورة الموقع التي احفظها
لانني اريد ان تنحفظ في المجلد وينحفظ مسارها في القاعدة وكمان ابيها تنعرض
وتتحدث بعد الاضافة وكذلك اريد زر تعديل على الفورم بحيث اقدر اعد البيانات ولكم
جزيل الشكر والتقدير


الملفات المرفقة
.rar   hefa2012.rar (الحجم : 457.42 ك ب / التحميلات : 75)
الرد }}}
تم الشكر بواسطة:
#2
مثال اخر سوف تستفيدي منه


الملفات المرفقة
.rar   addimage.rar (الحجم : 92.79 ك ب / التحميلات : 105)
الرد }}}
تم الشكر بواسطة:
#3
المثال مرفق وهو بطريقة نسخ الملف الى مجلد البرنامج وتخزين اسم الصورة الى القاعدة







المثال
http://www.vba4a.com/upload//view.php?file=da2debd0b4

كلاس الفورم الاول
كود :
Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        If con.State = ConnectionState.Open Then
            con.Close()
        End If
        Try
            showdata()

        Catch ex As Exception
            MsgBox(Err.Description, MsgBoxStyle.Critical, "")

        End Try

    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        Me.Hide()
        frmadd.Show()

    End Sub

  
    Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles pic.TextChanged
        If pic.Text.Trim = "" Then Exit Sub
        If My.Computer.FileSystem.FileExists(Application.StartupPath & "\pics\" & pic.Text.Trim) = False Then
            PictureBox1.Image = Nothing
            Exit Sub
        Else

            PictureBox1.Image = Image.FromFile(Application.StartupPath & "\pics\" & pic.Text)

        End If

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Me.BindingContext(ds, "tb").Position -= 1
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Me.BindingContext(ds, "tb").Position += 1

    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        Me.BindingContext(ds, "tb").Position = 0

    End Sub

    Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
        Me.BindingContext(ds, "tb").Position = Me.BindingContext(ds, "tb").Count - 1

    End Sub

    Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
        Try
            If MsgBox("سيتم حذف الصورة في مجلد الصور ضمن مجلد البرنامج  مع السجل الحلي...هل انت متاكد؟", MsgBoxStyle.YesNo +  MsgBoxStyle.Critical) = MsgBoxResult.No Then Exit Sub
            Dim cm As New OleDb.OleDbCommand("delete from tb where tid=" & Val(tid.Text) & "", con)
            If IsNothing(PictureBox1.Image) = False Then
                PictureBox1.Image.Dispose()

            End If



            If My.Computer.FileSystem.FileExists(Application.StartupPath & "\pics\" & pic.Text) Then
                My.Computer.FileSystem.DeleteFile(Application.StartupPath & "\pics\" & pic.Text)

            End If







            If con.State = ConnectionState.Closed Then
                con.Open()
            End If
            cm.ExecuteNonQuery()
            showdata()

        Catch ex As Exception
            MsgBox(Err.Description, MsgBoxStyle.Critical, "")

        End Try


    End Sub

    Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click

        If IsNothing(PictureBox1.Image) = False Then
            PictureBox1.Image.Dispose()
        End If


        frmedit.tid.Text = tid.Text
        frmedit.pic.Text = pic.Text
        frmedit.tname.Text = tname.Text
        frmedit.Show()
        '   Me.Hide()
    End Sub
End Class

كلاس الاضافة
كود :
Public Class frmadd

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        If tname.Text.Trim = "" Or pic.Text.Trim = "" Then
            MsgBox("لا اسم ولا رابط صورة!", MsgBoxStyle.Critical, "")
            tname.Focus()
            Exit Sub
        End If

        Try
            Dim sf As String = IO.Path.GetFileName(pic.Text)

            Dim insert As New OleDb.OleDbCommand("insert into tb (tname,pic) values (@tname,@pic)", con)
            insert.Parameters.AddWithValue("@tname", OleDb.OleDbType.VarChar).Value = tname.Text
            insert.Parameters.AddWithValue("@pic", OleDb.OleDbType.VarChar).Value = sf

            If con.State = ConnectionState.Closed Then
                con.Open()
            End If

            If My.Computer.FileSystem.FileExists(Application.StartupPath & "\pics\" & sf) = False Then

                My.Computer.FileSystem.CopyFile(pic.Text, Application.StartupPath & "\pics\" & sf, True)


            End If
            insert.ExecuteNonQuery()

            showdata()
            Me.Hide()

            Form1.Show()

        Catch ex As Exception
            MsgBox(Err.Description, MsgBoxStyle.Critical, "")

        End Try

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim ofd As New OpenFileDialog
        ofd.Filter = "JPG (*.jpg)|*.jpg|GIF (*.gif)|*.gif"
        If ofd.ShowDialog = Windows.Forms.DialogResult.OK Then
            pic.Clear()
            pic.Text = ofd.FileName

        End If

    End Sub

    Private Sub pic_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles pic.TextChanged
        If pic.Text.Trim = "" Then Exit Sub
        If My.Computer.FileSystem.FileExists(pic.Text.Trim) = False Then
            PictureBox1.Image = Nothing
            Exit Sub
        End If
        PictureBox1.Image = Image.FromFile(pic.Text.Trim)
    End Sub

    Private Sub frmadd_FormClosing(ByVal sender As Object, ByVal e As  System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        If con.State = ConnectionState.Open Then
            con.Close()
        End If

    End Sub

    Private Sub frmadd_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        If con.State = ConnectionState.Open Then
            con.Close()
        End If
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        showdata()
        Form1.Show()
        Me.Hide()

    End Sub
End Class
كلاس التعديل
كود :
Public Class frmedit
    Dim picold As String = ""
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim ofd As New OpenFileDialog
        ofd.Filter = "JPG (*.jpg)|*.jpg|GIF (*.gif)|*.gif"
        If ofd.ShowDialog = Windows.Forms.DialogResult.OK Then
            picold = pic.Text
            pic.Clear()
            pic.Text = ofd.FileName

        End If

    End Sub

    Private Sub pic_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles pic.TextChanged
        If pic.Text.Trim = "" Then Exit Sub
        If My.Computer.FileSystem.FileExists(Application.StartupPath & "\pics\" & pic.Text.Trim) = False Then
            PictureBox1.Image = Nothing
            Exit Sub
        Else

            PictureBox1.Image = Image.FromFile(Application.StartupPath & "\pics\" & pic.Text)

        End If


    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        If tname.Text.Trim = "" Or pic.Text.Trim = "" Then
            MsgBox("لا اسم ولا رابط صورة!", MsgBoxStyle.Critical, "")
            tname.Focus()
            Exit Sub
        End If

        Try
            Dim sf As String = IO.Path.GetFileName(pic.Text)

            Dim insert As New OleDb.OleDbCommand("update tb set  tname=@tname,pic=@pic where tid=" & Val(tid.Text) & "", con)
            insert.Parameters.AddWithValue("@tname", OleDb.OleDbType.VarChar).Value = tname.Text
            insert.Parameters.AddWithValue("@pic", OleDb.OleDbType.VarChar).Value = sf

            If con.State = ConnectionState.Closed Then
                con.Open()
            End If

            If My.Computer.FileSystem.FileExists(Application.StartupPath & "\pics\" & sf) = False Then
                My.Computer.FileSystem.CopyFile(pic.Text, Application.StartupPath & "\pics\" & sf, True)

            End If



            insert.ExecuteNonQuery()




            showdata()
            Me.Hide()
            '  Form1.Show()
        Catch ex As Exception
            MsgBox(Err.Description, MsgBoxStyle.Critical, "")

        End Try



    End Sub

    Private Sub frmedit_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        ListBox1.Items.Clear()

        Dim sf As String = ""
        For Each fl In IO.Directory.GetFiles(Application.StartupPath & "\pics\")
            sf = IO.Path.GetFileName(fl)
            Dim cm As New OleDb.OleDbCommand("select pic from tb where pic='" & sf & "'", con)
            If con.State = ConnectionState.Closed Then
                con.Open()
            End If
            Dim dr As OleDb.OleDbDataReader = cm.ExecuteReader
            If dr.Read = False Then
                ListBox1.Items.Add(sf)
            End If
        Next
        lbl.Text = "Count: " & ListBox1.Items.Count
        Button5.Enabled = True
    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        showdata()
        Form1.Show()
        Me.Hide()
    End Sub

  
    Private Sub ListBox1_SelectedIndexChanged(ByVal sender As  System.Object, ByVal e As System.EventArgs) Handles  ListBox1.SelectedIndexChanged
        lbl.Text = "Count: " & ListBox1.Items.Count & " curent index: " & ListBox1.SelectedIndex

    End Sub

    Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
        Try
            For x = 0 To ListBox1.Items.Count - 1
                My.Computer.FileSystem.DeleteFile(Application.StartupPath & "\pics\" & ListBox1.Items.Item(x))

            Next

            Button5.Enabled = False
        Catch ex As Exception

        End Try
    End Sub
End Class

الموديول
كود :
Module Module1
    Public str As String = "provider=microsoft.ace.oledb.12.0;data source=|datadirectory|\db.accdb"
    Public con As New OleDb.OleDbConnection(str)
    Public sql As String = "select * from tb"

    Public ds As New DataSet
    Public da As New OleDb.OleDbDataAdapter(sql, con)

    Public Sub showdata()
        Try
            ds.Clear()
            Form1.tid.DataBindings.Clear()
            Form1.tname.DataBindings.Clear()
            Form1.pic.DataBindings.Clear()

            da.Fill(ds, "tb")

            Form1.tid.DataBindings.Add("text", ds, "tb.tid")
            Form1.tname.DataBindings.Add("text", ds, "tb.tname")
            Form1.pic.DataBindings.Add("text", ds, "tb.pic")

        Catch ex As Exception
            MsgBox(Err.Description, MsgBoxStyle.Critical, "")

        End Try


    End Sub
End Module
الرد }}}
تم الشكر بواسطة: ola
#4
سلمت يمناك ياخوي سعود ويعطيك الف عافية لقد وجدت ماكنت ابحث عنه
لك مني اجمل التحايا
الرد }}}
تم الشكر بواسطة:
#5
بس عندي سؤال ممكن كيف اعمل تقرير للبيانات ولك جزيل الشكر ياخوي سعود

وكذلك لو عندي فورمين الفورم الاول به البيانات والصور

والفورم الثاني به ازرار

مثلاً لو ابي اعمل زر في الفورم الثاني بحيث لمن اضغط عليه يفتح لي الفورم الاول اول سجل مثلا
ومثلا زر اخر يفتح لي كمان الفورم الاول السجل رقم 3 وهكذا هل يمكنني عمل هذا
الرد }}}
تم الشكر بواسطة:
#6
hefa كتب :بس عندي سؤال ممكن كيف اعمل تقرير للبيانات ولك جزيل الشكر ياخوي سعود

وكذلك لو عندي فورمين الفورم الاول به البيانات والصور

والفورم الثاني به ازرار

مثلاً لو ابي اعمل زر في الفورم الثاني بحيث لمن اضغط عليه يفتح لي الفورم الاول اول سجل مثلا
ومثلا زر اخر يفتح لي كمان الفورم الاول السجل رقم 3 وهكذا هل يمكنني عمل هذا


[COLOR="#800080"]السلام عليكم

يرجى طرح هذا السؤال في القسم المخصص له (قسم اسئلة التقارير) [/COLOR]


يرجى الالتزام بقوانين المنتدى وكتابة المواضيع والمشاركات
الرد }}}
تم الشكر بواسطة:
#7
sajad كتب :[COLOR="#800080"]السلام عليكم

يرجى طرح هذا السؤال في القسم المخصص له (قسم اسئلة التقارير) [/COLOR]


يرجى الالتزام بقوانين المنتدى وكتابة المواضيع والمشاركات

بارك الله فيك اخوي فعلا الالتزام بالتنظيم هو لمصلحة الجميع وليس بالضرورة ان يكون من يعرف الربط بالقاعدة يعرف لبرمجة التقارير(من وجهة نظري وانا واحد من هؤلاء)
الرد }}}
تم الشكر بواسطة: ola



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


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