none
System.Data.ConstraintException was unhandled by user code RRS feed

  • Question

  • hi!

    it's my first time here...

    i have an asp website, and a dataset with a datatable which contains one field (103 records approx.).

    when i check i after configuring it it shows all the data,

    but when i bind a dropdownlist to it i get this exception:

    System.Data.ConstraintException was unhandled by user code
      Message="Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints."
     

    th ecode behind for the control in the load event  is:

    KiwiSymbolDTTableAdapter kiwiadapter = new KiwiSymbolDTTableAdapter();

    KiwiSymbolDropDownlist.DataSource = kiwiadapter.GetData();

    KiwiSymbolDropDownlist.DataBind();

     

    thanks alot


     

    Tuesday, January 8, 2008 7:36 AM

Answers

  • You have a mismatch between the constraints defined in your DataSet and the constraints actually present in your database.  For instance, you may have defined a column with AllowDBNulls = false when the underlying table actually allows nulls.  When GetData() pulls data from the database (indeed, when any process adds DataRows to a DataTable), the DataTable checks the constraints on every DataRow it's adding, and throws an exception if the DataRow violates a constraint.

     

    What you can do to identify the problem:  Before calling GetData(), set EnforceConstraints to false on the DataTable.  Set it back to true after calling GetData(), catch the exception, and iterate through the Rows collection.  Check each row's RowError property.  That property will contain an error message that will tell you exactly which constraint the row violates, and that will tell you what part of your DataSet you need to fix.

    Tuesday, January 8, 2008 5:39 PM
  • Try the solution in the thread below by copy your code to a new location drop the old one and create new one.

     

    http://forums.asp.net/p/1016934/1368836.aspx

    Thursday, January 10, 2008 2:15 PM

All replies

  • You have a mismatch between the constraints defined in your DataSet and the constraints actually present in your database.  For instance, you may have defined a column with AllowDBNulls = false when the underlying table actually allows nulls.  When GetData() pulls data from the database (indeed, when any process adds DataRows to a DataTable), the DataTable checks the constraints on every DataRow it's adding, and throws an exception if the DataRow violates a constraint.

     

    What you can do to identify the problem:  Before calling GetData(), set EnforceConstraints to false on the DataTable.  Set it back to true after calling GetData(), catch the exception, and iterate through the Rows collection.  Check each row's RowError property.  That property will contain an error message that will tell you exactly which constraint the row violates, and that will tell you what part of your DataSet you need to fix.

    Tuesday, January 8, 2008 5:39 PM
  • sorry, but which part should take care of that?

    the adapter doesn't have that property neither the dropdown list...

    could you be more specific?

    thnx

    • Proposed as answer by kulkedar Tuesday, October 12, 2010 2:00 PM
    Wednesday, January 9, 2008 6:52 AM
  • Try the solution in the thread below by copy your code to a new location drop the old one and create new one.

     

    http://forums.asp.net/p/1016934/1368836.aspx

    Thursday, January 10, 2008 2:15 PM