Save a System.Drawing.Color in the db

  • Thread starter Thread starter Richard Brunet
  • Start date Start date
R

Richard Brunet

Hi,
I have a DataTable that has a Color type DataColumn. I use
OleDbDataAdapter.Update(myTable) to update the db. Is there a place(an
event?) where i can do a type conversion from Color to string (or int) so
that the value can be saved in the db? What is the preferred way of
saving/reading Color DataColumns in the db? The point is the call to
OleDbDataAdapter.Update(myTable) appears to be atomic an offers no event to
do such a conversion. Therefore, you end up with a string column in the db,
and an incompatible Color DataColumn in your DataTable ! I'm caught with
this.

Thanks for any help!
 
Hi Richard,

You can convert from a Color to an Int32 using Color.ToArgb() and store the
int value in the database. To retrive the Color use FromArgb(int32) to
convert from the int back to a Color
 
I know Chris, the thing is WHEN can i do this? I recall that i use
OleDbDataAdapter.Update(myTable) where myTable schema has a Color column,
and the database has a corresponding string column (could change for an int
too depending on the solution). I want to avoid doing the conversion on the
client side (within the form code) using Binding.Parse and Format ... I'm
looking for a server-side solution so the server can send to the client a
DataTable containing a System.Drawing.Color column, not an Int32 column
(which would be more natural for the client side...).

Thanks .
 
Back
Top