Question Inserting Images through dataset.

dsk96m

Well-known member
Joined
Jan 11, 2013
Messages
173
Programming Experience
1-3
This deals with images and parent child tables.

I have an app that has a parent table and a child table. The child table will hold images. There is a 1 to (0 to many) relationship between these tables. There can be several images associate with a record in the parent table. I am trying to figure out how to browse for an image, and add it to the dataset and relate it to the parent record. The later part I have done. My issue is with adding adding an image and being able to add multiple image.

This is part of the app that i am adding the images. Obviously the browse opens a file dialog for selecting the image.
8-29-2013 9-11-52 AM.jpg

This is the code behind the Browse button:
VB.NET:
    Private Sub BrowseSimpleButton_Click(sender As System.Object, e As System.EventArgs) Handles BrowseSimpleButton.Click
        AddtoCardButton.Enabled = False
        If OpenFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
            Me.CardimageBindingSource.AddNew()
            ImagePictureEdit.Image = Image.FromFile(OpenFileDialog1.FileName)
            AddtoCardButton.Enabled = True
        End If
    End Sub

Not sure what to do for the save. I know i have to use something like this:

VB.NET:
        Dim ms As New MemoryStream()
        ImagePictureEdit.Image.Save(ms, ImagePictureEdit.Image.RawFormat)
        Dim data As Byte() = ms.GetBuffer

        me.cardimage.bindingsource.endedit

I know it is something along those lines, but the issue is the ImagePictureEdit.Image.Save(ms, ImagePictureEdit.Image.RawFormat).

Any help would be appreciated.
 
Well I think I got it, but just need to figure out why the child table is not saving on save. The parent ID flows down correctly on save, but the child table doesnt.

VB.NET:
    Private Sub BrowseSimpleButton_Click(sender As System.Object, e As System.EventArgs) Handles BrowseSimpleButton.Click
        Me.System_setupBindingSource.EndEdit()
        Me.Aircraft_conditionBindingSource.EndEdit()
        Me.FlightcardBindingSource.EndEdit()
        AddtoCardButton.Enabled = False
        If OpenFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
            Me.CardimageBindingSource.AddNew()
            ImagePictureEdit.Image = Image.FromFile(OpenFileDialog1.FileName)
            AddtoCardButton.Enabled = True
        End If
    End Sub

    Private Sub AddtoCardButton_Click(sender As System.Object, e As System.EventArgs) Handles AddtoCardButton.Click
        Dim ms As New MemoryStream()
        ImagePictureEdit.Image.Save(ms, ImagePictureEdit.Image.RawFormat)
        Dim data As Byte() = ms.GetBuffer

        Dim currentrow As DataRow = CardimageBindingSource.Current.row
        currentrow.Item("image") = data
        currentrow.Item("notes") = Me.NotesMemoEdit.Text
        currentrow.EndEdit()
        Me.CardimageBindingSource.EndEdit()

        Me.AddtoCardButton.Enabled = False
    End Sub
 
Back
Top