J.Sperandio
J.Sperandio

Reputation: 117

How I can treat null value in vb6 ResultSet

I have a return value from the database but I can not filter the null value.

With rs_receita
    Do Until .EOF
        Set noaux2 = xml.createElement("Superavit")
        noaux2.Text = IIf(IsEmpty(!Superavit), "", CStr(!Superavit))
        Call noaux.appendChild(noaux2)
      .MoveNext
    Loop
End With
Set rs_receita = Nothing

Upvotes: 3

Views: 1973

Answers (2)

Jeremy
Jeremy

Reputation: 4838

In VB6 (I'm sorry!) you can force coercion to a string by appending an empty string to the field value.

Edit: Phew, this article is a blast from the past. It gives a bunch of NULL handling ideas for classic VB6: https://technet.microsoft.com/en-us/library/Aa175775(v=SQL.80).aspx

I believe either of the following will work:

noaux2.Text = "" & rs("Superavit")

OR

noaux2.Text = vbNullString & rs("Superavit")

Upvotes: 1

Bond
Bond

Reputation: 16311

Avoid IIf for this scenario. IIf always evaluates both expressions. So when !Superavit is null, this will cause an error.

A single-line If statement, on the other hand, will only evaluate the expression to be executed. Combine that with the IsNull() function to reliably assign a database value to a variable if it's not null:

If IsNull(!Superavit) Then noaux2.Text = "" Else noaux2.Text = CStr(!Superavit)

Upvotes: 2

Related Questions