LoadDataRow question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Dennis C. Drumm

    LoadDataRow question

    The description for DataTable.LoadD ataRow says:
    Finds and updates a specific row. If no matching row is found, a new row is
    created using the given values.

    So I would think from that, that I should be able to fill the object[] array
    with values that correspond with each column of that row, and if a row in
    the table is found with the same value in the PrimaryKey column, then the
    row would be updated with the values in the array. But instead, I get the
    error:

    A first chance exception of type 'System.Data.Co nstraintExcepti on' occurred
    in system.data.dll

    Additional information: Failed to enable constraints. One or more rows
    contain values violating non-null, unique, or foreign-key constraints.


    What have I missed here? Does LoadDataRow update a row's values?

    Thanks,

    Dennis


  • Nicholas Paldino [.NET/C# MVP]

    #2
    Re: LoadDataRow question

    Dennis,

    The exception comes from the fact that the data table that you are
    adding the row to requires something to be populated. For example, one
    column might require a non-null value, but you are passing null.

    You will have to check the constraints and make sure you are passing the
    correct values in.

    Hope this helps.


    --
    - Nicholas Paldino [.NET/C# MVP]
    - mvp@spam.guard. caspershouse.co m

    "Dennis C. Drumm" <developer@prim acode.com> wrote in message
    news:OX2UdsfrDH A.488@tk2msftng p13.phx.gbl...[color=blue]
    > The description for DataTable.LoadD ataRow says:
    > Finds and updates a specific row. If no matching row is found, a new row[/color]
    is[color=blue]
    > created using the given values.
    >
    > So I would think from that, that I should be able to fill the object[][/color]
    array[color=blue]
    > with values that correspond with each column of that row, and if a row in
    > the table is found with the same value in the PrimaryKey column, then the
    > row would be updated with the values in the array. But instead, I get the
    > error:
    >
    > A first chance exception of type 'System.Data.Co nstraintExcepti on'[/color]
    occurred[color=blue]
    > in system.data.dll
    >
    > Additional information: Failed to enable constraints. One or more rows
    > contain values violating non-null, unique, or foreign-key constraints.
    >
    >
    > What have I missed here? Does LoadDataRow update a row's values?
    >
    > Thanks,
    >
    > Dennis
    >
    >[/color]


    Comment

    • Dennis C. Drumm

      #3
      Re: LoadDataRow question

      Thanks Nicholas:

      It turns out I needed to Table.AcceptCha nges() before the LoadDataRow, then
      everthing will work fine.

      Dennis

      "Nicholas Paldino [.NET/C# MVP]" <mvp@spam.guard .caspershouse.c om> wrote in
      message news:uC027CgrDH A.2064@TK2MSFTN GP11.phx.gbl...[color=blue]
      > Dennis,
      >
      > The exception comes from the fact that the data table that you are
      > adding the row to requires something to be populated. For example, one
      > column might require a non-null value, but you are passing null.
      >
      > You will have to check the constraints and make sure you are passing[/color]
      the[color=blue]
      > correct values in.
      >
      > Hope this helps.
      >
      >
      > --
      > - Nicholas Paldino [.NET/C# MVP]
      > - mvp@spam.guard. caspershouse.co m
      >
      > "Dennis C. Drumm" <developer@prim acode.com> wrote in message
      > news:OX2UdsfrDH A.488@tk2msftng p13.phx.gbl...[color=green]
      > > The description for DataTable.LoadD ataRow says:
      > > Finds and updates a specific row. If no matching row is found, a new row[/color]
      > is[color=green]
      > > created using the given values.
      > >
      > > So I would think from that, that I should be able to fill the object[][/color]
      > array[color=green]
      > > with values that correspond with each column of that row, and if a row[/color][/color]
      in[color=blue][color=green]
      > > the table is found with the same value in the PrimaryKey column, then[/color][/color]
      the[color=blue][color=green]
      > > row would be updated with the values in the array. But instead, I get[/color][/color]
      the[color=blue][color=green]
      > > error:
      > >
      > > A first chance exception of type 'System.Data.Co nstraintExcepti on'[/color]
      > occurred[color=green]
      > > in system.data.dll
      > >
      > > Additional information: Failed to enable constraints. One or more rows
      > > contain values violating non-null, unique, or foreign-key constraints.
      > >
      > >
      > > What have I missed here? Does LoadDataRow update a row's values?
      > >
      > > Thanks,
      > >
      > > Dennis
      > >
      > >[/color]
      >
      >[/color]


      Comment

      Working...