how to correct this code...

May 14, 2014 at 8:54 PM
hi Diego,

I know you are busy with a lot of work, when you are free let me know what you think of this code. I could not save a new record into the database and there was no exceptions too.
however, the updateDesign() works fine which is just as the code below.

Am I missing something in the following code:
Private Sub saveDesign(ByRef cc As List(Of Control))
    Using tran As LUNA.LunaTransactionBox = LUNA.LunaContext.CreateTransactionBox
        tran.TransactionBegin()
        'Dim dobj As Design_masterDAO = New Design_masterDAO
        Dim desob As New Design_master
        Dim result As Integer = 0
        Try
            desob.DesignID = TryCast(cc(0), TextBox).Text
            desob.DesignName = TryCast(cc(1), TextBox).Text
            desob.DesignDate = CDate(TryCast(cc(2), DateTimePicker).Value)
            desob.DesignCategory = TryCast(cc(3), ComboBox).Text
            desob.DesignDefaultPrice = CInt(TryCast(cc(4), TextBox).Text)
            desob.DesignRemarks = TryCast(cc(5), TextBox).Text
            desob.DesignImages = TryCast(cc(6), TextBox).Text

            Using dob As New Design_masterDAO
                result = dob.Save(desob)
            End Using
            tran.TransactionCommit()
        Catch ex As Exception
            tran.TransactionRollBack()
            MsgBox(ex.Message)
        End Try
    End Using
End Sub
Coordinator
May 15, 2014 at 10:14 AM
HI :) no problem for this.. so...

in your code first thing i see is that you use a very difficult system to retrive data from control. Is better to nominate explicity control, because in this mode if you change control on form your list of Control change position and your code don't work.

Next

If Luna don't save the record in database,maybe if your field DesignID is counter and key. If you fill them LunaEngine think is an update of an existing value .. the best thing to do is something like to this:

In Your Form you declare a Private _Id optional in Load method like this:
Private _IdToLoad as integer = 0 
public sub LoadForm(Optional IdToLoad as integer = 0)

_IdToLoad = IdToLoad

..some other code to fill control

end sub
next in your save method you make some like this:
Private Sub saveDesign()
    Using tran As LUNA.LunaTransactionBox = LUNA.LunaContext.CreateTransactionBox
        Dim desob As New Design_master

        if _idToLoad then
             desob.read(_idToLoad)
        end if 

        Dim result As Integer = 0
        Try
            
            desob.DesignName =txtName.Text
            desob.DesignDate =dtDesigndate.Value)
            desob.DesignCategory = cmbCat.Text
            desob.DesignDefaultPrice = txtPrice.Text)
            desob.DesignRemarks = txtRemark.Text
            desob.DesignImages = txtImg.Text
    
            tran.TransactionBegin()

            desob.Save()

            tran.TransactionCommit()

            result = desob.DesignID

        Catch ex As Exception
            tran.TransactionRollBack()
            MsgBox(ex.Message)
        End Try
    End Using
End Sub
Marked as answer by sathyasheelan on 5/15/2014 at 2:38 AM
May 15, 2014 at 10:42 AM
Hi Diego,

Will get it working like you suggested... you are something em... :) Thank you!
May 15, 2014 at 12:10 PM
Hi Diego,

What you suggested worked but for that pk had to be Auto-Increment field only. How do i Insert my own ID into the db ? Is there a function that creates new record before i fill the data in...
Coordinator
May 15, 2014 at 12:13 PM
You have to wait for newer version that check if is autoincrement or not to create the right save method. I'm testing new engine but i have many work so i'm a little slow to release newer version
May 15, 2014 at 12:29 PM
Don't break your head Diego,
Whatever you are doing it is just lovely, you keep on it. Your time is more important in creating there. Go where your passion flows. meanwhile I'll learn a bit of Italian myself. :)

Thanks !