Question Compare 3 user variables and raise an error if they didn't match

Lina

New member
Joined
Jul 22, 2022
Messages
2
Programming Experience
Beginner
Hi,

I'm using script task in SSIS package.
I'd like to compare 3 user variables (row count between 3 tables) and raise an error if they are not equal. Otherwise it's is a success.
I'm new in C# developpment.

I need your help.

Thanks
Lina
 
What C# tutorials have you already gone through? Conditional statements is usually one of the early topics covered.

Show us your code. We are not a code writing service, but we can help guide you towards a solution.
 
Far too many people expect code to appear out of thin air. Code is just an implementation of logic. The logic is the same as you would use in any manual process. If you were in a maths class and you were told to compare three variables, I bet you could do it. In that case, you can work out what the logic is. You need to do that first, then try to write code to implement that logic, then post a question if you encounter an actual issue doing that. You can explain your logic, show us the code you have and explain how it doesn't meet your needs.
 
Sorry!
Here is the code i'm triying

My script:
public void Main()
        {
            //// TODO: Add your code here

            Dts.TaskResult = (int)ScriptResults.Success;
            //         //MessageBox.Show(Dts.Variables["User::RowCtn_src1"].Value.ToString());
            //         //MessageBox.Show(Dts.Variables["User::RowCtn_src2"].Value.ToString());
            //         //MessageBox.Show(Dts.Variables["User::RowCtn_src3"].Value.ToString());
            Dts.Variables["User::RowCtn_src1"].Value = "";
            Dts.Variables["User::RowCtn_src2"].Value = "";
            Dts.Variables["User::RowCtn_src3"].Value = "";
            Dts.Variables["User::Err"].Value = "";



            if ("User::RowCtn_src1" != "User::RowCtn_src2" || "User::RowCtn_src1" != "User::RowCtn_src3" || "User::RowCtn_src2" = !"User::RowCtn_src3")

            {
                    this.Dts.Events.FireError(0, "Invalid row counts", "error", string.Empty, 0);
                    Dts.TaskResult = ScriptResults.Failure;
                
                //// i'd like to throw an error

            }

            //I've tried this one

            //             //this what I want :
            //             //if it's true the success otherwise raise un error'
            //             //How can I do it

            //int RowCtn_src1 = (int)this.Dts.Variables["RowCtn_src1"].Value;
            //int RowCtn_src2 = (int)this.Dts.Variables["RowCtn_src2"].Value;
            //int RowCtn_src3 = (int)this.Dts.Variables["RowCtn_src3"].Value;
            //if (RowCtn_src1 != RowCtn_src2 || RowCtn_src1 != RowCtn_src3 || RowCtn_src2 !=RowCtn_src3 ) 
            //{
            //    this.Dts.Events.FireError(0, "Invalid row counts", "error", string.Empty, 0);
            //    Dts.TaskResult = ScriptResults.Failure;
            //}


        }
 
You realise that this:
C#:
if ("User::RowCtn_src1" != "User::RowCtn_src2" || "User::RowCtn_src1" != "User::RowCtn_src3" || "User::RowCtn_src2" = !"User::RowCtn_src3")
is just comparing strings, right? If you want to compare variables then do that, rather than comparing string literals.
 
Back
Top Bottom