RE: DataTable.RemoveRow

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Kevin Yu [MSFT] (v-kevy_at_online.microsoft.com)
Date: 02/10/04


Date: Tue, 10 Feb 2004 12:20:04 GMT

Hi JT,

I have retried to reproduce the contraint exception according to your
description, but failed. As far as I know, the unique constraint only works
when you are adding rows to the table. It doesn't affect the
DataAdapter.Fill method.

I think the best way to merge the data, is to import rows one by one in a
loop. We can fill the new rows into another DataSet and use
DataTable.ImportRow method to get the rows from the new DataSet. When the
constraint is violate, an ConstraintException is thrown. We can handle the
exception and do nothing in the exception handler. The row will not be
added to the table. After the loop, all valid rows will be added to the
table. Here is an example:

        foreach(DataRow dr in dataset2.Table1.Rows)
        {
                try
                {
                        this.dataSet1.Table1.ImportRow(dr);
                }
                catch(ConstraintException)
                {
                }
        }

Hope this helps. If this doesn't work, please feel free to let me know. I'm
standing by to be of assistance.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."



Relevant Pages

  • Re: do task constraints constrain subtasks?
    ... communicate what is happening. ... realistic picture of what is meant to happen. ... I guess I take exception to the statement that, ... tasks under the summary there is an overall constraint. ...
    (microsoft.public.project)
  • Re: Constraint Exception from Web Service
    ... capturing the constraint error in the web service and then threw it back to ... the page as a soap exception. ...
    (microsoft.public.dotnet.framework.webservices.enhancements)
  • How to extract from the exception the reason for the failure
    ... the INSERT statement, UPDATE statement, or foreign key update caused ... constraint or unique index identified by "1" constrains table "XXX" ... I want to be able to assess the exception and to return a specific ...
    (comp.lang.java.programmer)
  • Re: Error recovery durring AddNew
    ... trying to figure out why the EndCurrentEdit clears the dataset's item ... some OTHER exception occurs, not just the one for this constraint. ... Didn't know you had the constraint in the dataset. ... >> exception occurs ALL of the data in the items collection for the new row ...
    (microsoft.public.dotnet.framework.windowsforms.databinding)
  • Re: long double versions of functions in gcc under Cygwin
    ... rather than the nearest enclosing one) and a decent exception ... them it doesn't seem like goto usage would be affected ... int typfun() ... Why use a for loop when it is just a while loop in disguise? ...
    (comp.lang.c)