perpetual_dream

Hello,

I have a picture box who is bound to an image column in the dataset.

Code Snippet

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

me. load_company_details()

End Sub

''' Binds the picturebox to the company_settings.Company_Logo column

Private Sub load_company_details()

ds.Tables.Clear()

ds.Clear()

ds = Me.companyprovider.select_all_from_company_datatset()

Me.piccompany.DataBindings.Clear()

Me.txttitle.DataBindings.Clear()

Dim bind As Binding = New System.Windows.Forms.Binding("Image", ds, "Dim bind As Binding = New System.Windows.Forms.Binding("Image", ds, "company_settings.Company_Logo")")

Dim bind2 As Binding = New System.Windows.Forms.Binding("Text", ds, "company_settings.Company_Name")

AddHandler bind.Format, AddressOf PictureFormat

Me.piccompany.Refresh()

Me.piccompany.DataBindings.Add(bind)

Me.txttitle.DataBindings.Add(bind2)

End Sub

Private Sub PictureFormat(ByVal sender As Object, ByVal e As ConvertEventArgs)

' e.Value is the original value

Dim img() As Byte = CType(e.Value, Byte())

Dim ms As New MemoryStream()

Dim offset As Integer = 0

ms.Write(img, offset, img.Length - offset)

Dim bmp As New Bitmap(ms)

ms.Close()

' Writes the new value back

e.Value = bmp

End Sub

'' updates the value of the image column in the database

Private Sub ButtonSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsavecompanydetails.Click

Try

If (Me.txtimagefile.Text = String.Empty Or Me.txttitle.Text = String.Empty) Then

MessageBox.Show("Complete both form fields prior to submitting", "Missing Values", _

MessageBoxButtons.OK, MessageBoxIcon.Exclamation)

Exit Sub

End If

Dim fs As FileStream = New FileStream(mImageFilePath.ToString(), FileMode.Open)

Windows.Forms.Cursor.Current = Cursors.WaitCursor

Dim img As Byte() = New Byte(fs.Length) {}

fs.Read(img, 0, fs.Length)

fs.Close()

Windows.Forms.Cursor.Current = Cursors.Default

mImageFile = Image.FromFile(mImageFilePath.ToString())

mImageFile = Nothing

company_settings.company_image = img

company_settings.company_name = Me.txttitle.Text

Me.companyprovider.update_company_settings()

Me.load_company_details()

Me.btneditcompanydetails.Enabled = True

Me.btnsavecompanydetails.Enabled = False

Me.txttitle.Enabled = False

Me.btnbrowse.Enabled = False

Catch ex As Exception

MessageBox.Show(ex.Message.ToString(), "File Test Error")

Exit Sub

End Try

End Sub

The problem that the data in picture box shows the update on form load and never does when I click the save button~~~~

Any Ideas

Thanks



Re: Visual Basic Express Edition The bound control data doesn't update!

tattoo

Hi Perpetual_Dream....

I am wondering where you are expecting your code to actually do the update

is it in the routine "Me.companyprovider.update_company_settings()"

If so, you would need to post the actual update code for anyone to be able to make any suggestions.





Re: Visual Basic Express Edition The bound control data doesn't update!

perpetual_dream

Yea in that routine ... here is the code... it actually updates Smile yet, the change doesn't appear unless i re-load the form... Smile

Code Snippet

Public Function update_company_settings() As Boolean

Try

command.Parameters.Clear()

command.CommandText = "update company_settings set company_name=@company_name1, company_logo=@company_logo1 where company_id='1'"

command.Parameters.AddWithValue("@company_logo1", companydetails.company_image)

command.Parameters.AddWithValue("@company_name1", companydetails.company_name)

connection.Close()

connection.Open()

command.ExecuteNonQuery()

connection.Close()

Catch ex As Exception

connection.Close()

MsgBox(ex.Message)

Return False

End Try

End Function





Re: Visual Basic Express Edition The bound control data doesn't update!

js06

I can't say for sure but if it doesn't show the changes untill you reload then you probably need to call the fill method again.

Basically when you reload the form that is what is happening

Look at your form load code

you can add this method again after your save






Re: Visual Basic Express Edition The bound control data doesn't update!

perpetual_dream

Here is the function that returns the dataset............. I am clueless

Code Snippet

Public Function select_all_from_company_dataset() As DataSet

Try

command.Parameters.Clear()

command.CommandText = "select * from company_settings where company_id='1'"

connection.Close()

da.SelectCommand = command

da.Fill(ds, "company_settings")

'da.Update(ds)

Return ds

Catch ex As Exception

MsgBox(ex.Message)

Return Nothing

End Try

End Function





Re: Visual Basic Express Edition The bound control data doesn't update!

perpetual_dream

anyone >

Please this is urgent....





Re: Visual Basic Express Edition The bound control data doesn't update!

js06

What is the code in your form's load event

since this is when you can see the changes (loading the form)

If you call that code again, will it show your changes






Re: Visual Basic Express Edition The bound control data doesn't update!

perpetual_dream

i already called it but it doesn't work.... i think it has 2 do with the binding... here it is Smile

Code Snippet

Private Sub load_company_details()

ds.Tables.Clear()

ds.Clear()

ds = Me.companyprovider.select_all_from_company_datatset()

Me.piccompany.DataBindings.Clear()

Me.txttitle.DataBindings.Clear()

Dim bind As Binding = New System.Windows.Forms.Binding("Image", ds, "company_settings.Company_Logo")")

Dim bind2 As Binding = New System.Windows.Forms.Binding("Text", ds, "company_settings.Company_Name")

AddHandler bind.Format, AddressOf PictureFormat

Me.piccompany.Refresh()

Me.piccompany.DataBindings.Add(bind)

Me.txttitle.DataBindings.Add(bind2)

End Sub





Re: Visual Basic Express Edition The bound control data doesn't update!

js06

Ok why not try to cheat a little

set it up where you can run the save

then close the form and load the form

Basically force it to do what it does when you reload

If this is your main form then you have a problem

you need to either have another form open and set your app to close when last form closes

or use this form as a child form

Sloppy but it might be the quick fix you need






Re: Visual Basic Express Edition The bound control data doesn't update!

perpetual_dream

any other opinions