Recordset NULL values return type mismatch error.

Results 1 to 3 of 3

Thread: Recordset NULL values return type mismatch error.

  1. #1
    K. Wilder Guest

    Default Recordset NULL values return type mismatch error.

    I&#039ve written a VB 6.0 component that retrieves records from SQL Server 7.0. Occasionally any particular column of a record might be NULL and when I try to set a variable to that item I get a "Type Mismatch" error. <BR><BR>I can continue to retrieve other records if I include "On Error Resume Next", but is this normal or am I doing something wrong?<BR><BR>Any help will be appreciated.<BR><BR>Thanks,<BR><BR>King Wilder<BR>

  2. #2
    SPG Guest

    Default My Guess...

    ... is that you have properly typed variables, as is good practice (you know, "dim iFoo as integer") and when you go to associate that with the recordset values, it sees iFoo = "" and dies at you.<BR><BR>If this isn&#039t the case (you&#039re using nothing but variants or strings), try using the "format()" function as you&#039re setting the variable:<BR>strFoo = format(objRS("NULL_FIELD"))<BR><BR>The format function will return a blank string when used like that.<BR><BR>HiH

  3. #3
    Join Date
    Dec 1969

    Default RE: Recordset NULL values return type mismatch err

    When a record has NULL value (really NULL, not just an empty string), there is literally no data for the Recordset to pass back to you. The type mismatch occurs because VB doesn&#039t allow you to assign NULL to any variable (I don&#039t think you can even assign Null to a VARIANT - Empty is used instead to signify a Variant holds no data). Your problems will be fixed by simply not assigning NULL values to variables. To ensure you don&#039t, use the IsNull() function to determine whether a field&#039s value is NULL or not:<BR><BR>If Not IsNull(rs.Fields("Field1")) Then<BR> Var1 = rs.Fields("Field1")<BR>Else<BR> Var1 = "" &#039Perform our own initialization of variable<BR>End If<BR><BR>Hope this helps...<BR><BR><BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts