StrataFrame Forum

SQL field type needed for a serializable BO field

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

By Greg McGuffey - 11/22/2006

I was going to try out this serializable thingy, i.e. try to store a bitmap (are other image types supported?) in a table field. What should the SQL column be defined as? varbinary? varchar?
By Trent L. Taylor - 11/22/2006

You will use a VarBinary(MAX) for SQL Server 2005 and Image for SQL Server 2000.
By Greg McGuffey - 11/22/2006

Thanks!



Next question: how do you allow a user to upload an image into this sort of field, so it can be saved?
By StrataFrame Team - 11/22/2006

The column will be created as a Byte[] field on the business object, so if you set the field to any byte array, then you can just save it and it will dump it to the database. 

However, if you're talking about letting your users upload things on your website... I'm not sure.  There are controls you can use to upload objects to your webserver, and there might be one in the basic ASP.NET controls, but I've never used one.

By Greg McGuffey - 11/22/2006

Actually, I'm talking about WinForms. I think I might have figured it out. Something like:





' imageFile is the full path to an image

MyPictureBox.Image = CType(New Bitmap(imageFile), Image)





If MyPictureBox is bound via SF, then saving it should save the serialized bitmap back to db right?
By Greg McGuffey - 11/22/2006

Ah...one more question (ok, maybe there will be more): How do I handle NULLs in the BO? I.e. the image may not be required, so how do I handle that. The Generic Nullable didn't work. What is an appropriate replacement value?
By Trent L. Taylor - 11/22/2006

f MyPictureBox is bound via SF, then saving it should save the serialized bitmap back to db right?

Correct. 

The Generic Nullable didn't work. What is an appropriate replacement value?

Just return an alternate value and put something like this:

New CType(System.Drawing.Bitmap(1,1), System.Drawing.Image)
By Greg McGuffey - 11/22/2006

Thanks!