Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How To Code This IF Statement
Message
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Titre:
How To Code This IF Statement
Divers
Thread ID:
01394340
Message ID:
01394340
Vues:
83
I have 2 classes with the same properties on them. If in AddMode, I want to instantiate the first, if in EditMode, the other.
I then want to pass the object into a method on another class. I get an error after the IF saying oProc does not exist in the current scope.

I could set the params and call ExecuteNonQuery from inside both the IF and the ELSE, but I hate to copy & paste the same lines of code. Is there another way to do this?
public override int SaveChanges()
{
    if (this.State == RecordState.AddMode)
    {
        csClass1 oProc = new csClass1();
    }
    else
    {
        csClass2 oProc = new csClass2();
    }

    oProc.iCompanyKey = this.iRecordId;
    oProc.sCompanyName = _sCompanyName;

    int iRetVal = csAppDataAccess.ExecuteNonQuery(oProc);

    if (csAppDataAccess.oException != null)
    {
        this.oException = csAppDataAccess.oException;
    }

    return iRetVal;
}
Everything makes sense in someone's mind
public class SystemCrasher :ICrashable
In addition, an integer field is not for irrational people
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform