Record is empty but gets displayed..

  • I just switched from Access to SQL but there is one thing I do not understand. When I manually make a field empty, the field is really empty ().

    When I display that record on a webpage, it will not show up (because it is empty, I got a script for that).

    But when I do a update of the field with an update statement through a web form in which the data written to the field (source is a ->emty<- text box in a form on a ASP page) the value is not set to although nothing was inserted in the field and it also has not a value of , it is just empty.

    I tried: If (Recordset.Fields.Item("thefield").Value) ="" THEN

    Response.write ""

    Else

    Response.write "error"

    %>

    Nothing should get displayed on the page (the first response.write should get executed) but I get the second response.write as a result. I do not ubderstand this since the record is empty, although the value is not

    Can anyone help?

  • i believe you are dealing with the difference between and empty string and a null value.  There should be somekind of isnull functionality within your code, but if there isn't in the SQL that gathers your recordset you can use the SQL isnull() function to return an empty string if the field is null.

    If the field name was widget then

    select isnull(widget,'') from tTableName

    would return an empty string whenever the field did not have a value and the code you have would work properly.

     

    If the phone doesn't ring...It's me.

  • Thanks Charles for your help, it helped. I found the solution, it is quite simple 😎

    If (Recordset.Fields.Item("thefield")) = "" or ISNULL(Recordset.Fields.Item("thefield")) THEN

    - without the .value

    - both = "" and ISNULL

    Also, I changed the database field to varchar (300)

    hurray!

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply