Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Where is the right place for record validation function?
Message
De
27/07/2006 23:36:11
 
 
À
Tous
Information générale
Forum:
ASP.NET
Catégorie:
The Mere Mortals .NET Framework
Titre:
Where is the right place for record validation function?
Divers
Thread ID:
01140952
Message ID:
01140952
Vues:
52
Hi Kevin,

I will write some validation of the record entered by the user b4 saving. For example I want to
check a unique combination of fields for the record (candidate key). Should I do this in the
borules.vb? I have tried doing the below from the example given in the help
(inserting at the bottom of borules.vb):
Public Function ValidateLveRecord(ByVal tclvrnoee As String, _
       ByVal tclvrcdleave As String, ByVal tdlvrleave As Nullable(Of DateTime)) As String
       Dim message As String = Nothing
       Dim dao As mmDataAccessBase = DirectCast(Me.HostObject, _
		mmBusinessObject).GetDataAccessObject()
       Dim Connection As IDbConnection
       Dim Reader As IDataReader = dao.ExecReader _
           ("SELECT * FROM vxlves WHERE clvrnoee=@tclvrnoee AND clvrcdleave=@tclvrcdleave AND " & _
           "dlvrleave=@tdlvrleave", Connection, New IDbDataParameter() _
           {dao.CreateParameter("@tclvrnoee", tclvrnoee), dao.CreateParameter("@tclvrcdleave", _ 
	   tclvrcdleave), dao.CreateParameter("@tdlvrleave", tdlvrleave)})
        If Reader.Read() Then
           message = "(Employee# + Leave Type + Date From) must be unique"
           If Not (Me.DataSet Is Nothing) Then
               Me.AddErrorProviderBrokenRule("CustomerID", message)
           End If
       End If
       Reader.Close()
       Return message
End Function
I have got a warning in that the "Variable 'Connection' is passed by reference before it has been
assigned a value. A null reference exception could result at runtime."

My questions:

1. Am I doing at the right place?
2. If yes, how do I suppress the warning message?
3. For the line "Me.AddErrorProviderBrokenRule("CustomerID", message)", what should I put as the
first parameter to replace CustomerID since this is a combination of fields?

Thanks in advance.
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform