Sending error message to log reading SQL
I have a scenario in my test where I need to make sure that the field A in a table doesnt save as null. If it does, I want to send an error message to the log. But although, one field is null in my recordset, I dont see the error message getting posted to the log. Instead, the values for that field gets posted as null or whatever the actual value of that field is. Below is what I am using in the script.
Const DB_CONNECT_STRING = "DSN=WRMSDB;UID=***;PWD=***;APP=Test Complete;WSID=**;DATABASE=***;"
Set myConn = CreateObject("ADODB.Connection")
Set myCommand1 = CreateObject("ADODB.Command" )
Set myCommand1.ActiveConnection = myConn
myCommand1.CommandText = "select * from TB_xyz "
set acttest = mycommand1.execute
while not acttest.eof
if acttest.fields("onefieldA").value = null then
log.Error ("field is null"), t.fields("fieldB").value
log.Message acttest.fields("fieldA").value , acttest.fields("fieldB").value
Solved! Go to Solution.
You probably need to use the IsNull function:
If IsNull(acttest.fields("onefieldA").value) Then ...
Of you may need to compare with Nothing:
If Not acttest.fields("onefieldA").value Is Nothing Then ...
See also: Nothing vs Empty vs Null
SmartBear Documentation Team Lead
Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️