Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Char Value in SQL Server

Status
Not open for further replies.

shangrilla

Programmer
Nov 21, 2001
360
0
0
US
name is a char field stored as null in the database. I send name to the following function, but It never returns true.


static private bool checkSpaces(char name)
{
bool val=false;
try
{
if (name.Equals("") || name.Equals(null) || Convert.IsDBNull(name))
val =true;
}
catch
{val= false;}
return val;
}
 
Convert.IsDBNull(value) returns true if and only if the value is of type TypeCode.DBNull; otherwise, false. "name" is a char , so never will return true.
name never will be equal to "" because name is a char and "" is a string.
Regarding your code:
name never will be equal to null because char is a value type and null is the NULL object.

-obislavu-



 
Right - you need to check for DBNull against the ADO field object, not a char-type object.

Chip H.


If you want to get the best response to a question, please check out FAQ222-2244 first
 
obislavu:

Thanks for your very descriptive explanation. Learning something new everyday. Do you know of a way to check if a char field is empty/null?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top