How do I "roll back" a bad new row in a dataset/table?

S

sherifffruitfly

Hi all,

I've got a datagrid bound to a dataset/table. When the OnRowChanging
event fires, the handler attempts to Insert the new record into the
database. When there's an error with this Insert operation, it gets
trapped (message displayed). The datagrid still displays the bad
record - I'd like to delete the record from the datagrid. All I (think
I) have available to me in the exception handler is the row itself
(Exception ex.Row). When I try ex.row.rejectchanges, I get a runtime
error dialog telling me:

"Cannot call CancelEdit inside an OnRowChanging event. Throw an
exception to cancel this update. Do you want to correct the value?"

How can I get the bad row off of my datagrid?

Thanks for any ideas,

cdj
 
M

mangist

Hi all,

I've got a datagrid bound to a dataset/table. When the OnRowChanging
event fires, the handler attempts to Insert the new record into the
database. When there's an error with this Insert operation, it gets
trapped (message displayed). The datagrid still displays the bad
record - I'd like to delete the record from the datagrid. All I (think
I) have available to me in the exception handler is the row itself
(Exception ex.Row). When I try ex.row.rejectchanges, I get a runtime
error dialog telling me:

"Cannot call CancelEdit inside an OnRowChanging event. Throw an
exception to cancel this update. Do you want to correct the value?"

How can I get the bad row off of my datagrid?

Thanks for any ideas,

cdj

Do what it says, throw an exception in the OnRowChanging event instead
of calling ex.Row.RejectChanges.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top