T
tshad
I have a query that is returning a null and I am testing for null. The
value being sent back is a varChar(11) from Sql Server. If I do the query
from Query Analyser I get NULL returned.
But if I run the following:
************************************************************
dbReader = myDbObject.RunProcedure("GetNewHire", parameters);
if (dbReader.Read())
{
if (dbReader["SSN"] == null)
ssn = "SSN is equal null";
else
ssn = "SSN is not equal null";
if(dbReader["FirstName"] != null)firstName = (string)dbReader["FirstName"];
if(dbReader["LastName"] != null)lastName = (string)dbReader["LastName"];
if(dbReader["MiddleInitial"] != null)middleInitial =
(string)dbReader["MiddleInitial"];
// if(dbReader["SSN"] != null)ssn = (string)dbReader["SSN"];
************************************************************
If I run this I get "SSN is not equal null". If I uncomment the last line,
I get an error:
System.InvalidCastException: Specified cast is not valid.
at MyFunctions.NewHire.GetNewHire(String& returnString)
at MyFunctions.NewHire.AddNewHire()
at TestDll.Class1.Main(String[] args) in
c:\vsprojects\testdll\class1.cs:line
24
Am I not doing the test correctly? I also tried using (dbReader["SSN"] !=
null), but got the same results.
Thanks,
Tom
value being sent back is a varChar(11) from Sql Server. If I do the query
from Query Analyser I get NULL returned.
But if I run the following:
************************************************************
dbReader = myDbObject.RunProcedure("GetNewHire", parameters);
if (dbReader.Read())
{
if (dbReader["SSN"] == null)
ssn = "SSN is equal null";
else
ssn = "SSN is not equal null";
if(dbReader["FirstName"] != null)firstName = (string)dbReader["FirstName"];
if(dbReader["LastName"] != null)lastName = (string)dbReader["LastName"];
if(dbReader["MiddleInitial"] != null)middleInitial =
(string)dbReader["MiddleInitial"];
// if(dbReader["SSN"] != null)ssn = (string)dbReader["SSN"];
************************************************************
If I run this I get "SSN is not equal null". If I uncomment the last line,
I get an error:
System.InvalidCastException: Specified cast is not valid.
at MyFunctions.NewHire.GetNewHire(String& returnString)
at MyFunctions.NewHire.AddNewHire()
at TestDll.Class1.Main(String[] args) in
c:\vsprojects\testdll\class1.cs:line
24
Am I not doing the test correctly? I also tried using (dbReader["SSN"] !=
null), but got the same results.
Thanks,
Tom