Home > Enterprise >  Confused about <type 'DBNull'> and empty strings
Confused about <type 'DBNull'> and empty strings

Time:09-09

I am really confused and hope someone can help.

I am working on a program that, when retrieving records from a SQL Server database, some of the fields can come back as null. One of the fields is named LaserName. Looking at the locals Window, the LaserName variable appears to just be a empty string.

But, when I use this code:

LaserName != ''

The code simply bypasses it as if the variable was not empty. When I looked at the type of that variable:

print(type(LaserName))

...the type returns <type 'DBNull'>. How do I look for DBNull in Python? Or is there a more elegant way to look for NULL values returned from a database?

CodePudding user response:

Converting the type to a string seems to have alleviated my problem.

if "DBNull" in str(type(wgtper))

  • Related