[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 204
  • Last Modified:

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

0
dwezil
Asked:
dwezil
  • 3
  • 3
2 Solutions
 
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
 
tiagosalgadoCommented:
But have you already check the myReader.GetString(0) value?
Maybe you're getting a different value from DB as you expected.
0
Veeam and MySQL: How to Perform Backup & Recovery

MySQL and the MariaDB variant are among the most used databases in Linux environments, and many critical applications support their data on them. Watch this recorded webinar to find out how Veeam Backup & Replication allows you to get consistent backups of MySQL databases.

 
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
 
tiagosalgadoCommented:
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

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now