determining "dirty" columns for DataRowState.Added

  • Thread starter Thread starter Jiho Han
  • Start date Start date
J

Jiho Han

I need to generatea list of columns that are "dirty" for a row to be inserted.

For an update scenario, I can compare values returned by DataRow[column,
DataRowState.Current] vs. DataRow[column, DataRowState.Original]. However,
I can't seem to find a way to do this for an insert scenario.

I've peeked at the framework's CommandBuilder code and it seems to run through
all columns except where the AllowDBNull is false but the value happens to
be null (that would mean it's dirty). But all columns of the tables I am
working with are set to AllowDBNull = True except for the PK column. That
means it will basically return all columns.

Does anyone know how to address the issue above?
Thanks

Jiho Ha
 
For dataset new rows, all columns are "dirty" in that they wouldn't exist
elsewhere.
 
Perhaps I am not being clear.

I want only the columns that were set to some value. This includes columns
that were explicitly set to null.
If you had a table with say 50 columns, and only 5 of them were set on insert,
I don't want the insert statement to set all 50 columns. The only the ones
that were modified should be determinable.
For dataset new rows, all columns are "dirty" in that they wouldn't
exist elsewhere.

I need to generatea list of columns that are "dirty" for a row to be
inserted.

For an update scenario, I can compare values returned by
DataRow[column, DataRowState.Current] vs. DataRow[column,
DataRowState.Original]. However, I can't seem to find a way to do
this for an insert scenario.

I've peeked at the framework's CommandBuilder code and it seems to
run through all columns except where the AllowDBNull is false but the
value happens to be null (that would mean it's dirty). But all
columns of the tables I am working with are set to AllowDBNull = True
except for the PK column. That means it will basically return all
columns.

Does anyone know how to address the issue above?
Thanks
Jiho Han
 
DataTable doesn't track which columns where explicitly set, so you would
have to listen to the DataTable.ColumnChanging event to track those columns
yourself. The other option would to have the DataColumn.DefaultValue set
and compare against that.

--
This posting is provided "AS IS", with no warranties, and confers no rights.
Please do not send email directly to this alias. This alias is for newsgroup
purposes only.

Jiho Han said:
Perhaps I am not being clear.

I want only the columns that were set to some value. This includes
columns that were explicitly set to null.
If you had a table with say 50 columns, and only 5 of them were set on
insert, I don't want the insert statement to set all 50 columns. The only
the ones that were modified should be determinable.
For dataset new rows, all columns are "dirty" in that they wouldn't
exist elsewhere.

I need to generatea list of columns that are "dirty" for a row to be
inserted.

For an update scenario, I can compare values returned by
DataRow[column, DataRowState.Current] vs. DataRow[column,
DataRowState.Original]. However, I can't seem to find a way to do
this for an insert scenario.

I've peeked at the framework's CommandBuilder code and it seems to
run through all columns except where the AllowDBNull is false but the
value happens to be null (that would mean it's dirty). But all
columns of the tables I am working with are set to AllowDBNull = True
except for the PK column. That means it will basically return all
columns.

Does anyone know how to address the issue above?
Thanks
Jiho Han
 
Sounds like listening to the ColumnChange event is the only option available.

As for the DataTable/Row keeping track of explicitly set values, it seems
to do that for update scenario since when I set a column to the exactly the
same value (no change in value) but it generated a DataTable when I called
GetChanges(). And subsequently, with CommandBuilder, it generated an update
sql. I will double-check however.

Thanks for your help.
Jiho
DataTable doesn't track which columns where explicitly set, so you
would have to listen to the DataTable.ColumnChanging event to track
those columns yourself. The other option would to have the
DataColumn.DefaultValue set and compare against that.

Perhaps I am not being clear.

I want only the columns that were set to some value. This includes
columns that were explicitly set to null.
If you had a table with say 50 columns, and only 5 of them were set
on
insert, I don't want the insert statement to set all 50 columns. The
only
the ones that were modified should be determinable.
For dataset new rows, all columns are "dirty" in that they wouldn't
exist elsewhere.


I need to generatea list of columns that are "dirty" for a row to
be inserted.

For an update scenario, I can compare values returned by
DataRow[column, DataRowState.Current] vs. DataRow[column,
DataRowState.Original]. However, I can't seem to find a way to do
this for an insert scenario.

I've peeked at the framework's CommandBuilder code and it seems to
run through all columns except where the AllowDBNull is false but
the value happens to be null (that would mean it's dirty). But all
columns of the tables I am working with are set to AllowDBNull =
True except for the PK column. That means it will basically return
all columns.

Does anyone know how to address the issue above?
Thanks
Jiho Ha
 
Back
Top