Home All Groups Group Topic Archive Search About

Q: Expressions in DataColumns

Author
1 May 2006 1:19 PM
G .Net
Hi

I've run into a problem when using Expressions in a DataColumn of a
DataTable which I'm updating back to the underlying databas. That is, I'm
loading data into a DataTable in which I've set some of the DataColumns to
calculate their contents using the Expression property.

This all works fine until I try and transfer these calculated values back to
the SQL database. When I try to do this, I get the exception message:

"The column mapping from SourceColumn 'Col 1' failed because the DataColumn
'Col 1' is a computed column"

Is there anyway I can override this exception so the values are written back
to the database?

Geoff

Author
1 May 2006 8:43 PM
Mark Ashton
You can handle the RowUpdating event and the adapter and copy the value from
the DataRow to the appropriate parameter on the command.

For example,
SqlDataAdapter adapter = ...;
adapter.RowUpdating += delegate(object sender, SqlRowUpdatingEventArgs args)
{
    args.Command.Parameters["X"].Value = args.Row["X"];
};
adapter.Update(...);

Show quote
"G .Net" wrote:

> Hi
>
> I've run into a problem when using Expressions in a DataColumn of a
> DataTable which I'm updating back to the underlying databas. That is, I'm
> loading data into a DataTable in which I've set some of the DataColumns to
> calculate their contents using the Expression property.
>
> This all works fine until I try and transfer these calculated values back to
> the SQL database. When I try to do this, I get the exception message:
>
> "The column mapping from SourceColumn 'Col 1' failed because the DataColumn
> 'Col 1' is a computed column"
>
> Is there anyway I can override this exception so the values are written back
> to the database?
>
> Geoff
>
>
>
Author
2 May 2006 8:33 AM
G .Net
Hi Mark

I'm afraid I don't follow. Could you explain further?

G

Show quote
"Mark Ashton" <MarkAsh***@discussions.microsoft.com> wrote in message
news:F94461C4-C59C-46A2-8403-19CD886D683C@microsoft.com...
> You can handle the RowUpdating event and the adapter and copy the value
> from
> the DataRow to the appropriate parameter on the command.
>
> For example,
> SqlDataAdapter adapter = ...;
> adapter.RowUpdating += delegate(object sender, SqlRowUpdatingEventArgs
> args)
> {
>    args.Command.Parameters["X"].Value = args.Row["X"];
> };
> adapter.Update(...);
>
> "G .Net" wrote:
>
>> Hi
>>
>> I've run into a problem when using Expressions in a DataColumn of a
>> DataTable which I'm updating back to the underlying databas. That is, I'm
>> loading data into a DataTable in which I've set some of the DataColumns
>> to
>> calculate their contents using the Expression property.
>>
>> This all works fine until I try and transfer these calculated values back
>> to
>> the SQL database. When I try to do this, I get the exception message:
>>
>> "The column mapping from SourceColumn 'Col 1' failed because the
>> DataColumn
>> 'Col 1' is a computed column"
>>
>> Is there anyway I can override this exception so the values are written
>> back
>> to the database?
>>
>> Geoff
>>
>>
>>

AddThis Social Bookmark Button