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

dwezilAsked:
Who is Participating?
 
tiagosalgadoConnect With a Mentor Commented:
But have you already check the myReader.GetString(0) value?
Maybe you're getting a different value from DB as you expected.
0
 
tiagosalgadoCommented:
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
0
 
dwezilAuthor Commented:
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
0
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

 
dwezilAuthor Commented:
yeah Ive checked, there is a value of 00000 in the table
0
 
dwezilAuthor Commented:
and its in the correct column that myreader is reading
0
 
tiagosalgadoConnect With a Mentor Commented:
There's something strange in that. If statemente is not skipped if you realy getting the "00000" string. Try to re-check your value, make a breakpoint at your if statement and make a watch for your myReader.GetString(0) value.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.