Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How To Code This IF Statement
Message
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Title:
How To Code This IF Statement
Miscellaneous
Thread ID:
01394340
Message ID:
01394340
Views:
82
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
Next
Reply
Map
View

Click here to load this message in the networking platform