Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints.
2014-02-28 16:22
459 查看
System.Data.ConstraintException: Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints.
at System.Data.DataTable.EnableConstraints()
at System.Data.DataTable.set_EnforceConstraints(Boolean value)
at System.Data.DataTable.EndLoadData()
遇到这个错误 Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints.
请参考msdn文章来debug找出错误的地方: http://msdn.microsoft.com/en-us/library/system.data.datatable.geterrors(VS.71).aspx
它检查DataSet中的所有DataTable的HasErrors属性,然后对有错误的DataTable使用GetErrors方法。
GetErrors返回一组DataRows,检查返回的所有DataRow的RowError属性来获得确切的错误信息。
具体错误将显示在日志中
at System.Data.DataTable.EnableConstraints()
at System.Data.DataTable.set_EnforceConstraints(Boolean value)
at System.Data.DataTable.EndLoadData()
遇到这个错误 Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints.
请参考msdn文章来debug找出错误的地方: http://msdn.microsoft.com/en-us/library/system.data.datatable.geterrors(VS.71).aspx
它检查DataSet中的所有DataTable的HasErrors属性,然后对有错误的DataTable使用GetErrors方法。
GetErrors返回一组DataRows,检查返回的所有DataRow的RowError属性来获得确切的错误信息。
DataTable dataTable = new DataTable() int returnValue = 0; try { returnValue = this.Adapter.Fill(dataTable); } catch (System.Data.DataException e) { System.Data.DataRow[] rowsInError; System.Text.StringBuilder sbError = new System.Text.StringBuilder(); // Test if the table has errors. If not, skip it. if (dataTable.HasErrors) { // Get an array of all rows with errors. rowsInError = dataTable.GetErrors(); // Print the error of each column in each row. for (int i = 0; i < rowsInError.Length; i++) { foreach (System.Data.DataColumn column in dataTable.Columns) { sbError.Append(column.ColumnName + " " + rowsInError[i].GetColumnError(column)); } // Clear the row errors rowsInError[i].ClearErrors(); } } string time = System.DateTime.Now.ToString(); var fileName = "Error.log"; string filePath = System.Web.HttpContext.Current.Server.MapPath(fileName); System.IO.FileStream fst = new System.IO.FileStream(filePath, System.IO.FileMode.Append); System.IO.StreamWriter swt = new System.IO.StreamWriter(fst, System.Text.Encoding.GetEncoding("utf-8")); swt.WriteLine("======================"); swt.WriteLine(time); swt.WriteLine("----------------------"); swt.WriteLine(sbError.ToString()); swt.WriteLine("----------------------"); swt.WriteLine(e.ToString()); swt.Close(); fst.Close(); } return returnValue;
具体错误将显示在日志中
====================== 2/27/2014 11:47:54 PM ---------------------- CustomerID ParentCustomerID CustomerNumber Column 'CustomerNumber' exceeds the MaxLength limit.Name StatementName Inactive OnHold EMailAddress TimeStamp ShippingMethodID PriceLevel TradeDiscount TaxExempt ClassID UserDefine1 UserDefine2 CreditLimitType TimeStamp1 ActivationCode ---------------------- System.Data.ConstraintException: Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints. at System.Data.DataTable.EnableConstraints() at System.Data.DataTable.set_EnforceConstraints(Boolean value) at System.Data.DataTable.EndLoadData() at System.Data.Common.DataAdapter.FillFromReader(DataSet dataset, DataTable datatable, String srcTable, DataReaderContainer dataReader, Int32 startRecord, Int32 maxRecords, DataColumn parentChapterColumn, Object parentChapterValue) at System.Data.Common.DataAdapter.Fill(DataTable[] dataTables, IDataReader dataReader, Int32 startRecord, Int32 maxRecords) at System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) at System.Data.Common.DbDataAdapter.Fill(DataTable[] dataTables, Int32 startRecord, Int32 maxRecords, IDbCommand command, CommandBehavior behavior) at System.Data.Common.DbDataAdapter.Fill(DataTable dataTable) at Nodus.Applications.EPay.Data.EntitiesTableAdapters.CustomerTableAdapter.FillByKeyword(CustomerDataTable dataTable, String Keyword, Nullable`1 MaxResults)
相关文章推荐
- 源码调试Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints.
- Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints.
- Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints.
- Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints.
- Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints
- DataTable - Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints
- DataSet hell - "Failed to enable constraints. One or more rows contain values...."
- dell装机bios问题 os install mode enable failed to detect one or more drives during post
- One or more layers failed to draw. Spatial index does not exist
- Failed to instantiate one or more classes
- Geoserver fails One or more listeners failed to start
- 关于Struts2报错严重: One or more Filters failed to start. Full details will be found in the appropriate co
- Cannot change version of project facet Dynamic Web Module to 2.5. 和 One or more constraints have not
- One or more listeners failed to start. Full details will be found in the appropriate container log
- 启动 Tomcat 报错 One or more listeners failed to start. Full details will be found in the appropriate
- one or more listeners failed to start
- Tomcat 8报错 SEVERE: One or more listener failed to start,如何找到更详细的错误信息
- arcgis的One or more layers failed to draw: 问题
- bug笔记 - Spring --- Tomcat 报错: SEVERE: One or more listeners failed to start.
- android的imageView出现failed to instantiate one or more classes