I have a CSV file that I read into my automation, I use the value of SerialNumber in an SQL search with my NativeSearch from Snowflake. I save the output to a new DataTable but continue to get “Object reference not set to an instance of an object.”.
I can use an Output Data Table activity and see my data with a Write Line but cannot figure out how to actually manipulate the data without getting the above error.
Can anyone lend me insight or a resource to understand what I’m trying to do better?
-Make sure that you’ve properly initialized all the variables and objects you’re using in your automation. In your case, ensure that the DataTable you’re using to store the SQL query result is initialized before trying to manipulate the data.
-You can use the Build Data Table
activity to create an empty DataTable with the required column structure.
-Verify that the SQL query you’re executing using Snowflake is returning results. If there are no results, attempting to manipulate the data will result in a null DataTable.
-Ensure that the column names used in your DataTable match the names returned by your SQL query. If there is a mismatch, you might not be able to access the data.
-When working with objects like DataTables or DataRow objects, use the Is Nothing
check to ensure they are not null before trying to access their properties or data.
OR
Use this Linq:
From row In yourDataTable.AsEnumerable()
Where row.Field(Of String)("SerialNumber") = "YourSerialNumber"
Select New With {
.Column1 = row.Field(Of String)("Column1"),
.Column2 = row.Field(Of String)("Column2")
' Add more columns as needed
}
Check if any condition is used while reading the file
Object reference error will come only if value is null for a variable
I have my data table default value as “New DataTable”, am I properly assigning it?
I am able to do a for each loop after my first for each loop using my output DT from the SnowFlake call and get the very last item pulled. I am also able to write the line in the first for each loop to see all the headers and values.
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.