Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Correct way to add new record
Message
De
29/07/2006 13:30:43
 
 
À
Tous
Information générale
Forum:
ASP.NET
Catégorie:
The Mere Mortals .NET Framework
Titre:
Correct way to add new record
Divers
Thread ID:
01141525
Message ID:
01141525
Vues:
70
My web form can add a new customer record using business object. The new record is added when save button is clicked. I want to verify is that I am using the correct way to do it? My business object Called 'Customer'. Below are the steps I use to add new record.


1. Declare business object
    Protected customer As Customer
2. Instantiates the Customer business objects.
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        ' Instantiate the Customer object
        Me.customer = CType(Me.RegisterBizObj(New Customer), Customer)
	'
	'
3. In Page_Load Use NewRow() function to add new record and store the business object's DataSet into session.
        If Page.IsPostBack Then
            ' Retrieve the previous Customer DataSet
            Me.customer.DataSet = Session("dsCustomer")
        Else
            ' Add new record
            Me.oVxlve.NewRow()
            Session("dsCustomer") = Me.customer.DataSet
        End If
4. When save button clicked, retreive back DataSet from session. Then use Save() function to save the record into database.
    Protected Sub btnSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSave.Click
        Dim dsCustomer As DataSet = CType(Session("dsCustomer"), DataSet)
        Dim result As mmSaveDataResult

        result = Me.Save(Me.customer, dsCustomer, Me.customer.TableName)

        Select Case result
            Case mmSaveDataResult.RulesPassed
                MsgBox("Record Saved.")
             Case mmSaveDataResult.RulesBroken
                MsgBox(Me.customer.Rules.GetAllBrokenRules)
            Case mmSaveDataResult.RuleWarnings
                MsgBox(Me.customer.Rules.GetAllWarnings)
        End Select
    End Sub
Please correct me if I did something wrong. Thanks.
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform