Forum Discussion

testcmpleteuser's avatar
testcmpleteuser
Occasional Contributor
9 years ago
Solved

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. 

 

sub sqltest()

Const DB_CONNECT_STRING = "DSN=WRMSDB;UID=***;PWD=***;APP=Test Complete;WSID=**;DATABASE=***;"
Set myConn = CreateObject("ADODB.Connection")
Set myCommand1 = CreateObject("ADODB.Command" )
myConn.Open DB_CONNECT_STRING
Set myCommand1.ActiveConnection = myConn
myCommand1.CommandText = "select * from TB_xyz "
set acttest = mycommand1.execute
acttest.movefirst
while not acttest.eof
if acttest.fields("onefieldA").value = null then
log.Error ("field is null"), t.fields("fieldB").value
else
log.Message acttest.fields("fieldA").value , acttest.fields("fieldB").value
end if
acttest.movenext
wend
myConn.Close
end sub

  • 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

3 Replies

  • NisHera's avatar
    NisHera
    Valued Contributor

    in VB scripting comparison operator is "= =" you have used "="

    try if acttest.fields("onefieldA").value == null

  • HKosova's avatar
    HKosova
    SmartBear Alumni (Retired)

    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