Update and Add Data

Add New Record

This example demonstrates how to write a reusable function that programmatically constructs a database record and inserts the new record into the database. The reusable function can be called from any page.
Table Name
Select the name of the database table
Record Control Class
Select the record control class where the customization will be added
Field Name
Select an editable field in the table
Applies to
RecordClass class
''' Inserts a new record into the table. Start a transaction before
''' calling this function.
Public Shared Sub AddRecord()

    ' Create an empty record.
    Dim rec As New ${${Table Name}RecordClassName}

    ' Set the fields of the new record as follows.
    rec.${Field Name} = "1"

    ' Set more field values here...
    ' Insert the new record into the database.
    ' Save adds the record to the database but commit 
    ' happens when the page has completed its processing

    ' Example shown below calls AddRecord() function on a button click.
    ' Note that you need to add transaction handling as shown below.

    'Public Overrides Sub Button_Click(ByVal sender As Object, ByVal args As EventArgs)

    '    Try
    '        DbUtils.StartTransaction()
    '        OrdersRecord.AddRecord()
    '        DbUtils.CommitTransaction()
    '        Me.DataChanged = True

    '    Catch ex As Exception

    '        DbUtils.RollBackTransaction()

    '        Utils.MiscUtils.RegisterJScriptAlert(Me, "UNIQUE_SCRIPTKEY", ex.Message)

    '    Finally

    '        DbUtils.EndTransaction()

    '    End Try

    'End Sub

End Sub

Terms of Service Privacy Statement