web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Error when comparing r...
Power Automate
Answered

Error when comparing results from SQL queries: Object Reference Not Set to an instance of an object

(0) ShareShare
ReportReport
Posted on by 11

I have written a bot that works >90% of the time, but I keep getting an error and I need help. The bot executes two queries using Microsoft Access and then compares the output to see if the results are the same. It compares the exported datatables  on several dimensions including if the headers match, the number of rows match, the number of columns match, and the body of the queries match. However, the problem I'm having is that sometimes when comparing the body of the query, I get an "Object reference not set to an instance of any object" error. The query then quits and won't continue to execute.

 

The problem is that the two variables holding the results don't match, but then the query should just not trigger the IF statement and continue executing. I can't figure out why I'm getting the "object reference" error sometime (but not all the time). Here are screenshots:

 

Screenshot 1: shows the if statement that compares the two variables and the error (full error message pasted after the image). 

daw44_0-1646772888103.png

Full error message:

System.NullReferenceException: Object reference not set to an instance of an object.
at Microsoft.Flow.RPA.Desktop.Robin.Engine.Operators.Comparison.ComparisonCalculator.GenerateCalculatorKey(Type leftType, Type rightType, Type actualLeftType, Type actualRightType, Boolean& avoidTypeChecking)
at Microsoft.Flow.RPA.Desktop.Robin.Engine.Operators.Calculators.DataTableCalculator.Compare(Object left, Object right)
at Microsoft.Flow.RPA.Desktop.Robin.Engine.Operators.Calculators.DataTableCalculator.CompareDataTables(DataTable left, DataTable right)
at Microsoft.Flow.RPA.Desktop.Robin.Engine.Operators.Calculators.DataTableCalculator.EqualTo(DataTable left, DataTable right)
at Microsoft.Flow.RPA.Desktop.Robin.Engine.Operators.Calculators.CalculatorBase`1.ExecuteComparison(Object left, Object right, Func`3 comparisonMethod, Boolean& useNextCalculator)
at Microsoft.Flow.RPA.Desktop.Robin.Engine.Operators.Calculators.CalculatorBase`1.CompareImpl(Object left, ComparisonOperator operator, Object right, Boolean avoidTypeChecking)
at Microsoft.Flow.RPA.Desktop.Robin.Engine.Operators.Comparison.ComparisonCalculator.GetCalculatorAndCompare(Object left, ComparisonOperator operator, Object right, String calculatorKey, Boolean avoidTypeChecking)
at Microsoft.Flow.RPA.Desktop.Robin.Engine.Operators.Comparison.ComparisonCalculator.Compare(IRuntimeErrorHandler errorHandler, IContext context, Object left, ComparisonOperator operator, Object right)
at Microsoft.Flow.RPA.Desktop.Robin.Engine.Execution.ExpressionEvaluator.Visit(ComparisonExpression comparison)
at Microsoft.Flow.RPA.Desktop.Robin.Engine.Execution.ExpressionEvaluator.EvaluateAndCacheExpression(IEvaluatableContext expression)
at Microsoft.Flow.RPA.Desktop.Robin.Engine.Execution.StatementExecutionHandler.Visit(IIfStatement statement)
at Microsoft.Flow.RPA.Desktop.Robin.Engine.Execution.StatementExecutionHandler.ExecuteStatementWithException(IStatementWithException statement)
at Microsoft.Flow.RPA.Desktop.Robin.Engine.Execution.StatementExecutionHandler.Execute(IStatement statement)
at Microsoft.Flow.RPA.Desktop.Robin.Engine.Execution.StatementExecutionHandler.Visit(IfScope scope)
at Microsoft.Flow.RPA.Desktop.Robin.Engine.Execution.StatementExecutionHandler.Execute(IStatement statement)
at Microsoft.Flow.RPA.Desktop.Robin.Engine.Execution.StatementExecutionHandler.<>c__DisplayClass100_0.<ExecuteScope>g__ExecuteStatement|0(IStatement statement)
at Microsoft.Flow.RPA.Desktop.Robin.Engine.Execution.StatementExecutionHandler.ExecuteScope(IScope scope)
at Microsoft.Flow.RPA.Desktop.Robin.Engine.Execution.StatementExecutionHandler.ExecuteLoop(LoopBaseScope loopScope)
at Microsoft.Flow.RPA.Desktop.Robin.Engine.Execution.StatementExecutionHandler.Visit(LoopScope scope)
at Microsoft.Flow.RPA.Desktop.Robin.Engine.Execution.StatementExecutionHandler.Execute(IStatement statement)
at Microsoft.Flow.RPA.Desktop.Robin.Engine.Execution.StatementExecutionHandler.<>c__DisplayClass100_0.<ExecuteScope>g__ExecuteStatement|0(IStatement statement)
at Microsoft.Flow.RPA.Desktop.Robin.Engine.Execution.StatementExecutionHandler.ExecuteScope(IScope scope)
at Microsoft.Flow.RPA.Desktop.Robin.Engine.Execution.StatementExecutionHandler.ExecuteLoop(LoopBaseScope loopScope)
at Microsoft.Flow.RPA.Desktop.Robin.Engine.Execution.StatementExecutionHandler.Visit(LoopScope scope)
at Microsoft.Flow.RPA.Desktop.Robin.Engine.Execution.StatementExecutionHandler.Execute(IStatement statement)
at Microsoft.Flow.RPA.Desktop.Robin.Engine.Execution.StatementExecutionHandler.<>c__DisplayClass100_0.<ExecuteScope>g__ExecuteStatement|0(IStatement statement)
at Microsoft.Flow.RPA.Desktop.Robin.Engine.Execution.StatementExecutionHandler.ExecuteScope(IScope scope)
at Microsoft.Flow.RPA.Desktop.Robin.Engine.Execution.StatementExecutionHandler.Execute(IStatement statement)
at Microsoft.Flow.RPA.Desktop.Robin.Engine.Execution.Runner.Run(Program program, RunMode mode, ProcessArgument[] arguments, DebugInfo debugInfo)

 

Screenshot 2: shows the data in the QSolutionDataFull variable (so this variable is not null)

daw44_1-1646772958223.png

Screenshot 3: shows the data in the QSSolutionDataFull variable (so this variable is not null)

daw44_2-1646772983409.png

So clearly the results don't match, but why does the bot throw the error instead of just skip the if statement? How can I fix it so the bot continues to run?

 

I have tried the following (or ruled the following out) already:

1. I can replicate the same error using different SQL queries (so it is not just one query)

2. I verified the variables are both of the same data type (see image, they are both datatables) and the SQL executes (my code weeds out queries that don't work earlier in the process). 

3. I have verified that it works when the datatables match.

4. I have verified that it works most of the time when the datatables don't match.

5. I have changed the inequality with the same result

6. I have tried to search and find the problem in the forums and on the internet with no luck.

 

I would appreciate any help!

I have the same question (0)
  • VJR Profile Picture
    7,635 on at

    Hi @daw44 

     

    Not sure if its a good idea to use the "IF" comparison to directly compare two datatables.

     

    If as you say, that it works when the datatables match then you can add a "On block error" above the "IF" such that if it has an error it will not show up and silently continue/skip (to the location based on what you give in the On block error).

     

     

     

     

     

  • daw44 Profile Picture
    11 on at

    VJR,

    Do you have a better way to compare the contents of the query results than an if comparison? I'm open to suggestions. 

  • VJR Profile Picture
    7,635 on at

    Hi @daw44 

     

    I think you want to compare several things -

    So,

    - For comparing query results you would need to find a Join SQL query that compares two tables

    - For number of rows and number of columns - you can get from the Datatable's ColumnsCount and RowsCount property

    - For headers - The ColumnHeadersRow of a datatable gives a datarow that contains the table headers. So you can compare them once you get the ColumnHeadersRow values.

     

     

     

     

  • Verified answer
    daw44 Profile Picture
    11 on at

    VJR,

     

    Thanks for steering me in the right direction. I had the number of rows, columns, and headers working. I was able to use a UNION statement to test to see if the body was the same (then just check if rows equaled the solution query). It doesn't pick up sorting issues, but this seems good enough. I appreciate the help!

     

  • VJR Profile Picture
    7,635 on at

    Good to know you got it working through a Union query.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Automate

#1
11manish Profile Picture

11manish 233

#2
David_MA Profile Picture

David_MA 217 Super User 2026 Season 1

#3
Valantis Profile Picture

Valantis 190

Last 30 days Overall leaderboard