Monday, March 26, 2012

Many types of empty variables?

I wonder if there are many different types of empty variables.

The problem is I couldn't match two empty variables. When I debug it, I saw that both variables also nothing, but how come they couldn't match? One is from database. I look at the field of that table, there is no value in it. Another one, the value is " ".

In the past, I think I saw some terms like isempty, isnothing, isnull, "". Could it be because of that? What are the difference between them?

A null value in a field in a table is represented by DBNull.value in code.
dr("fieldname").Equals(DBNull.Value) will return true if fieldname does not have any value or is null

ToString() of a null field will give an empty string checked using
String.IsNullOrEmpty(dr("fieldname").ToString()) will return true if fieldname does not have any value or is null

dr is a DataReader


Ok, thanks. I think I got that fix now after I put a .empty to both variables.

0 comments:

Post a Comment