Infopath 2007 Repeating Table Nulls

344 views Asked by At

I am getting this error: Data Could not be read. Data is Null. This method or property cannot be called on Null values.

I know the Database has NULL values in some fields. I just want to handle them and continue filling in the next row. Here's some code:

rdr is the SqlDataReader

if (rdr[EmailID] != null)
{
     //this blows up on this line on the 32nd iteration of the loop when searching for an extended group.
     EmpNewData.SelectSingleNode("/my:myFields/my:Emp/my:EmpData/my:email", NamespaceManager).SetValue(rdr.GetString(EmailID));
 }
 else
 {
     EmpNewData.SelectSingleNode("/my:myFields/my:Emp/my:EmpData/my:email", NamespaceManager).SetValue("No.Email");
 }

I could handle this with the Stored Procedure, but I'd really like to know how to handle this. Above is one of many iterations I've tried. Thanks.

1

There are 1 answers

0
Sean On BEST ANSWER

I figured this out. IsDBNull seems to take care of it. I ran thru the code in debug to check where the ordinal sat. It was 14 in this case.

int EmailID = rdr.GetOrdinal("EmailID");

Then when using GetString:

if (!(rdr.IsDBNull(14)))
{
     EmpNewData.SelectSingleNode("/my:myFields/my:Emp/my:EmpData/my:email", NamespaceManager).SetValue(rdr.GetString(EmailID));
}
else
{
     EmpNewData.SelectSingleNode("/my:myFields/my:Emp/my:EmpData/my:email", NamespaceManager).SetValue("No Email");
}

I hope this will help somebody.