Link to home
Start Free TrialLog in
Avatar of dwezil
dwezilFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Trouble with If statement!

Hello, I have an if statement that changes a parameter's value depending on the value in a field that is selected earlier. The If statement should always run the if and the else because it is run in a loop and the value will be in one the the fields. I have replicated a previous IF that worked but for some reason it wont change the value of the parameter.

This is the working IF

 if (myReader2.GetString(1) == "RV")
            {
                OracleParameter accountnoParam = new OracleParameter(":AccountNo1", OracleType.VarChar, 200);
                accountnoParam.Value = "2320ACC";
                myCommand8.Parameters.Add(accountnoParam);
            }
            else
            {
                OracleParameter accountnoParam = new OracleParameter(":AccountNo1", OracleType.VarChar, 200);
                accountnoParam.Value = ddlAccountNo.SelectedValue;
                myCommand8.Parameters.Add(accountnoParam);
            }
This is the IF I'm having problems with
 
if (myReader.GetString(0) == "00000")
            {
                OracleParameter descripParam = new OracleParameter(":Description", OracleType.VarChar, 200);
                descripParam.Value = txtProjName.Text;
                myCommand3.Parameters.Add(descripParam);
            }
            else
            {
                OracleParameter descripParam = new OracleParameter(":Description", OracleType.VarChar, 200);
                descripParam.Value = myReader.GetString(2);
                myCommand3.Parameters.Add(descripParam);
            }

Open in new window

Avatar of tiagosalgado
tiagosalgado
Flag of Portugal image

Try to create the paremeter outside your loop. And then set only your value on it.
myCommand3.Parameters.Add(":Description", OracleType.VarChar, 200);
Then on your If statement use
myCommand3.Parameters[":Description"].Value = your_value
Avatar of dwezil

ASKER

OracleParameter descripParam = new OracleParameter(":Description", OracleType.VarChar, 200);
           
            if (myReader.GetString(0) == "00000")
            {
               
                descripParam.Value = txtProjName.Text;
                myCommand3.Parameters.Add(descripParam);
            }
            else
            {
               
                descripParam.Value = myReader.GetString(2);
                myCommand3.Parameters.Add(descripParam);
            }

tried this, it skips the IF and added the ELSE value
ASKER CERTIFIED SOLUTION
Avatar of tiagosalgado
tiagosalgado
Flag of Portugal image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of dwezil

ASKER

yeah Ive checked, there is a value of 00000 in the table
Avatar of dwezil

ASKER

and its in the correct column that myreader is reading
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial