DataRowChangeEventHandler Issue

  • Thread starter Thread starter Jeff Hagins
  • Start date Start date
J

Jeff Hagins

I have written a DataRowChangeEventHandler to act as
a "security" filter based on the current users "role". The
event handler needs to be able to reject/cancel Inserts to
the ADO.NET DataTable (these inserts are the results of a
Select against the dataSource using the Fill method on a
SqlDataAdapter).

I've tried throwing an exception inside the handler, which
doesn't appear to do anything. I've also tried calling
RejectChanges on the row. This seems to work, but also
seems to leave an invalid row in the table in a "Detached"
state, which causes things like AcceptChanges to blow up
later on.

I suspect I'm just going about this the wrong way, but
haven't seen an example anywhere of how to prevent a Row
from being added to a DataTable.

My code is shown below -- does anyone know what
the "right" way is to do this?

Thanks in advance,

Jeff

private void
FrameworkRowAddedSecurityMonitor(object sender,
IFrameworkTableSecurityEvent e)
{
if (e.Action == DataRowAction.Add)
{
if
(e.SecurityObject.DataType != null)
{
if
((e.SecurityObject.AccessMask &
ContentManager.FW_ACL_PERMISSION_READ) == 0)
{
// Option 1
DataRow
row = (DataRow) e.SecurityObject;

row.RejectChanges();

// Option 2
throw (new
ContentManagerSecurityException("Access
Denied",e.SecurityObject,ContentManager.FW_ACL_PERMISSION_R
EAD,e.SecurityObject.AccessMask));
}
}
}
}
 
$a101280a@phx.gbl:
I have written a DataRowChangeEventHandler to act as
a "security" filter based on the current users "role". The
event handler needs to be able to reject/cancel Inserts to
the ADO.NET DataTable (these inserts are the results of a
Select against the dataSource using the Fill method on a
SqlDataAdapter).

I suspect I'm just going about this the wrong way, but
haven't seen an example anywhere of how to prevent a Row
from being added to a DataTable.

Thanks in advance,

Jeff

Don't wait for an insert to occur to validate data!

Implement a business layer in your application. Do not pass a
DataSet/DataTable to the client. Instead pass your business objects.
Those object should have all the features the client needs. The business
objects are responsible for updating the data layer.

Need an example? See the latest template on my code generator site (see
signature).
 
I have done exactly the same as you are attempting and it works just
fine. I have defined my own exception (inherits ApplicationException)
and throwing this cancels updates and inserts on the table.

My application (Windows, not ASP) is very data-centric with very few
business rules (simple access control being one of them) so I decided
to pass typed datasets to the application.

Nils
 
Back
Top