How to prevent RowChanging event when filling dataset

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • J

    How to prevent RowChanging event when filling dataset

    I'm experimenting with strongly typed datasets, and when the .Fill method is
    called, the RowChanging fires for each row. This causes a problem when the
    existing data does not adhere to the rules outlined in the RowChanging
    method. Is there an easy way to not have the RowChanging event occur when
    the dataset is being filled?

    Example code is

    daTitleAuthor.F ill(dsAuthors1) ;

    private void tblTitleAuthor_ RowChanging(obj ect sender,
    dsAuthors.title authorRowChange Event e) {
    if ( !e.Row.Isroyalt yperNull() ) {
    if ( (e.Action == DataRowAction.A dd || e.Action == DataRowAction.C hange)
    && e.Row.royaltype r > 10) {
    throw new Exception("Roya lty cannot be greater than 10");
    }
    }
    }


  • Dmitriy Lapshin [C# / .NET MVP]

    #2
    Re: How to prevent RowChanging event when filling dataset

    Hi,

    What about unwiring the event handler before calling Fill and re-wiring it
    after the Fill has completed?

    --
    Dmitriy Lapshin [C# / .NET MVP]
    X-Unity Test Studio

    Bring the power of unit testing to VS .NET IDE

    "J" <sendspam@sends pam.com> wrote in message
    news:vo8vn570h7 er53@corp.super news.com...[color=blue]
    > I'm experimenting with strongly typed datasets, and when the .Fill method[/color]
    is[color=blue]
    > called, the RowChanging fires for each row. This causes a problem when[/color]
    the[color=blue]
    > existing data does not adhere to the rules outlined in the RowChanging
    > method. Is there an easy way to not have the RowChanging event occur when
    > the dataset is being filled?
    >
    > Example code is
    >
    > daTitleAuthor.F ill(dsAuthors1) ;
    >
    > private void tblTitleAuthor_ RowChanging(obj ect sender,
    > dsAuthors.title authorRowChange Event e) {
    > if ( !e.Row.Isroyalt yperNull() ) {
    > if ( (e.Action == DataRowAction.A dd || e.Action ==[/color]
    DataRowAction.C hange)[color=blue]
    > && e.Row.royaltype r > 10) {
    > throw new Exception("Roya lty cannot be greater than 10");
    > }
    > }
    > }
    >
    >[/color]

    Comment

    • J

      #3
      Re: How to prevent RowChanging event when filling dataset

      That's what I ended up doing. It just seemed so crude and code intensive, I
      was hoping there was a better way.

      "Dmitriy Lapshin [C# / .NET MVP]" <x-code@no-spam-please.hotpop.c om> wrote
      in message news:O%23oslckj DHA.3312@tk2msf tngp13.phx.gbl. ..[color=blue]
      > Hi,
      >
      > What about unwiring the event handler before calling Fill and re-wiring it
      > after the Fill has completed?
      >
      > --
      > Dmitriy Lapshin [C# / .NET MVP]
      > X-Unity Test Studio
      > http://x-unity.miik.com.ua/teststudio.aspx
      > Bring the power of unit testing to VS .NET IDE
      >
      > "J" <sendspam@sends pam.com> wrote in message
      > news:vo8vn570h7 er53@corp.super news.com...[color=green]
      > > I'm experimenting with strongly typed datasets, and when the .Fill[/color][/color]
      method[color=blue]
      > is[color=green]
      > > called, the RowChanging fires for each row. This causes a problem when[/color]
      > the[color=green]
      > > existing data does not adhere to the rules outlined in the RowChanging
      > > method. Is there an easy way to not have the RowChanging event occur[/color][/color]
      when[color=blue][color=green]
      > > the dataset is being filled?
      > >
      > > Example code is
      > >
      > > daTitleAuthor.F ill(dsAuthors1) ;
      > >
      > > private void tblTitleAuthor_ RowChanging(obj ect sender,
      > > dsAuthors.title authorRowChange Event e) {
      > > if ( !e.Row.Isroyalt yperNull() ) {
      > > if ( (e.Action == DataRowAction.A dd || e.Action ==[/color]
      > DataRowAction.C hange)[color=green]
      > > && e.Row.royaltype r > 10) {
      > > throw new Exception("Roya lty cannot be greater than 10");
      > > }
      > > }
      > > }
      > >
      > >[/color]
      >[/color]


      Comment

      Working...