J
James
The code below should it seems to me work but doesnt:
bool rowChanged = false;
foreach (DataColumn col in row.Columns)
if (col != row.Table.PrimaryKey[0])
if (col.DefaultValue != row[col])
rowChanged = true;
When debugging it I found that for a bool type column whose
DefaultValue is true and whose row[col] value is true, the code goes
into the last if statement and sets rowChanged to true. When I get
VS.Net Command window to print out the value of (col.DefaultValue !=
row[col]) it even says false. However somewhat suspiciously the full
dump of the variables col.DefaultValue and row[col] are different
although they imply their values are the same.
I seem to remember something about DataRow column values being held in
types which allow for a DBNull.Value value. So I may be trying to
compare two different types here I suspect.
However I can't find any way of cooercing an object into another type
where that type is held in a variable something like this:
System.Type tp;
object x = (tp)row[col];
I've had to write some hideous code which deals with all the different
possible types on a case by case basis.
Anyone got a better idea?
PS anyone who writes a reply asking why I want to do this without
suggesting any solution will get flamed
bool rowChanged = false;
foreach (DataColumn col in row.Columns)
if (col != row.Table.PrimaryKey[0])
if (col.DefaultValue != row[col])
rowChanged = true;
When debugging it I found that for a bool type column whose
DefaultValue is true and whose row[col] value is true, the code goes
into the last if statement and sets rowChanged to true. When I get
VS.Net Command window to print out the value of (col.DefaultValue !=
row[col]) it even says false. However somewhat suspiciously the full
dump of the variables col.DefaultValue and row[col] are different
although they imply their values are the same.
I seem to remember something about DataRow column values being held in
types which allow for a DBNull.Value value. So I may be trying to
compare two different types here I suspect.
However I can't find any way of cooercing an object into another type
where that type is held in a variable something like this:
System.Type tp;
object x = (tp)row[col];
I've had to write some hideous code which deals with all the different
possible types on a case by case basis.
Anyone got a better idea?
PS anyone who writes a reply asking why I want to do this without
suggesting any solution will get flamed