Cannot update a byte[] field

Posts   
 
    
bvalle
User
Posts: 54
Joined: 07-Jun-2006
# Posted on: 27-Jul-2007 16:56:21   

Hello

LLBLGen Pro 2.0 July 6th build. Adapter

I am trying to update a binary(32) field on a SQL 2005 database. When I do a insert the field is fine and I do not have any problems, however when I do a fetch, modify some of the bytes on the field and save again the field becomes all zeros on the database. The strange thing is if I do a refetch, by setting the refetch flag to true on the save method, the entity tells me the byte array is correct with my changes, however the database still wrong with all zeros.

Here is the sample code that I am trying to use to set the fields:


PathEntity pathEntity = new PathEntity();

pathEntity.PathID = 42;

using (DataAccessAdapter dataAccessAdapter = new DataAccessAdapter())
{
    dataAccessAdapter.FetchEntity(pathEntity);
}

pathEntity.RollingPathHistory[0] = 1;
pathEntity.RollingPathHistory[10] = 1;
pathEntity.RollingPathHistory[20] = 1;
pathEntity.RollingPathHistory[30] = 1;

using (DataAccessAdapter dataAccessAdapter = new DataAccessAdapter())
{
  dataAccessAdapter.SaveEntity(pathEntity,true); 
} /// correct on the entity here, but after save SQL 2005 says all the numbers are 0s

Please point me to the right direction, because right now I am a little lost.

Thank you, BV

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 28-Jul-2007 06:38:53   

You may change the values INSIDE the array, but the field doesn't know that, as the byte array doesn't signal that its internal values have changed. So you can alter the values inside the array, but the field will not see those changes and will stay 'unchanged'.

Try this:

...
byte[] tmpByte =  pathEntity.RollingPathHistory;

tmpByte[0] = 1;
tmpByte[10] = 1;
tmpByte[20] = 1;
tmpByte[30] = 1;

pathEntity = new byte[] {0};
pathEntity = tmpByte;
...

David Elizondo | LLBLGen Support Team
bvalle
User
Posts: 54
Joined: 07-Jun-2006
# Posted on: 30-Jul-2007 17:28:59   

Trying right now on the code, thanks.