hi, 

i have been having an endless problem with the save button for some time and i am also new in here.
Actually, here's how my problem defines:
i was developing my own project in the university so what i am stack is to have save button which firstly validates what the user enters the form. for instance if the user skips the text fields, i wanted to restrict the user to fill all the form and when he completes, the save must be accomplished. 
here's the code i was trying to put but i was having problem saying the windows.forms.etc is unable to convert the save as Boolean and something like that.

Dim success As Boolean
    Private Sub Save_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Save.Click
        If Product_DetailsBindingSource.Current Is Nothing Then
            MessageBox.Show("plz, select any feilds then click save button", Me.Text)
            success = False
        Else
            Me.Validate()
            success = DirectCast(Product_DetailsBindingSource.Current, products).Save()
            MessageBox.Show("i will save u ")
            Panel1.Show()
        End If

        MessageBox.Show("save has completed successfully")
        Panel1.Show()

End Sub

Recommended Answers

All 5 Replies

Please fix your post, its a bit confusing....

Why are you doing a directcast? Where did you get that from?

Why aren't you ending the bindingsource's Edit by using a .EndEdit?

Me.Validate()
Me.Product_DetailsBindingSource.EndEdit()
Me.Product_DetailsTableAdapter.Update(Me.WhateveryourDataSetisCalled.Product_Details)

Dim success As Boolean

Private Sub Save_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Save.Click

If Product_DetailsBindingSource.Current Is Nothing Then

MessageBox.Show("plz, fill any feilds then click save button", Me.Text)
success = False

Else

Me.Validate()
success = DirectCast(Product_DetailsBindingSource.Current,products).Save()
MessageBox.Show("info has saved successfully ")

End If

or you can replace the second condition of if statement by save function code
me.validate()
me.produc........endedit()
me.prod..........update and so on)

always i receive the first option of the if statement even if i fill all the text fields, it prompts the first condition (" plz, fill the txt fields)

i dont what to do, plz help me

Ok... if you say so...

I've never done data validation in this manner.

I took a sample data application that uses a version of the NorthWind Sample database and placed the following code in OrdersBindingSource_PositionChanged event.

MessageBox.Show(OrdersBindingSource.Current Is Nothing)

And it returned False every time I changed from order to order, or added an order. It never returned True (Meaning the the Current was something)

So if that's the case... I have to wonder why you are updating (or saving) a record for Products with the Product_DetailsBindingSource?

Shouldn't there be a ProductsBindingSource?

Did that solve your problem? Please mark this thread solved.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.