StrataFrame Forum

Images and Null Values

http://forum.strataframe.net/Topic13598.aspx

By Bill Cunnien - 1/21/2008

I do not know what happened.  All was going quite well.  The demo Friday was excellent...no errors in the presentation.  One of the users suggested that I reimport our part data so that the two systems are synchronized on Monday.  No problem.  I had the SQL script ready to fire in that event. 

Last night I ran the import.  No problems.

Today, users are sending me lots of error windows.  In my initial investigation, I ran across a problem with the image field in the part table.  It was working fine before, but now it won't handle null data.  This just doesn't make sense.  I ran the DevEx update to the most recent control suite and also reset the Inherited UI project.  No problems with that; however, that makes no difference. 

What could I have done to mess up my image handling?

Thanks!
Bill

By Bill Cunnien - 1/21/2008

The specific error that I am getting is "{"Unable to cast object of type 'System.DBNull' to type 'System.Byte[]'."}". 

This is the property code on which the error occurs:

public System.Byte[] sketch
{
   
get
   
{
       
return (System.Byte[])this.CurrentRow["sketch"];  <---error fires on this line!
    }
   
set
   
{
       
this.CurrentRow["sketch"] = value;
    }
}

I thought I would try the old replace value on null trick, but I cannot seem to get the C# syntax right.  But, then I keep thinking that I did not have to do that before the import.  It was working fine with the code above. 

Thoughts, anyone?
Bill

By Bill Cunnien - 1/21/2008

I added the following syntax to the replacement value:

new byte[] {}

That works...but I still do not know what went wrong.

Doze

By Trent L. Taylor - 1/21/2008

I see how the error manifested itself, but I am not sure what changed between your versions.  Your correction is the same thing that I would have done...but without further investigation I am not sure I could give you a straight answer Smile
By Bill Cunnien - 1/21/2008

No biggie...I will take a pragmatic approach on this one.  It is working, so I'll just tip-toe as I walk by any of that code in the future.
By StrataFrame Team - 1/23/2008

Seems to be that when you had the version working, there were no NULL values in the database for your testing data, but when you merged the two databases, several of the images were missing and were replaced by NULLs.  BTW, by default, a StrataFrame business object will insert an empty array for a byte[] field, so any new rows generated through the business objects would not have thrown the error.  However, when you set the AllowNullValuesOnNewRow property to true, the NULL value is not replaced, so you could then end up with NULL values in that field.