Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints.
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属性来获得确切的错误信息。
DataTable dataTable = new DataTable()
int returnValue = ;
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 = ; 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.的更多相关文章
- InnoDB和Foreign KEY Constraints
InnoDB表中中Foreign Key定义 1. InnoDB允许a foreign key引用一个索引列或者索引组列. 2. InnoDB现在并不支持用户定义的分区表有foreign keys,这 ...
- 解决Windows8下Cisco Systems VPN Client的Reason 442: Failed to Enable Virtual Adapter错误
Windows8下使用Cisco Systems VPN Client创建的Cisco IPSec VPN无法连接,提示Reason 442: Failed to Enable Virtual Ada ...
- WIN8 下Cisco VPN连接 出现vpn 422 failed to enable virtual adapter错误
今天在家用VPN软件连接,出现了“vpn 422 failed to enable virtual adapter”的错误,系统安装的是Win8专业版32位,百度了半天又很多方法解决不了,后来发现了一 ...
- 解决Cisco VPN Client:Reason 442: Failed to Enable Virtual Adapter VPN连接问题
大公司里肯定涉及不同地点的办公问题,这样VPN的使用就频繁了,今天遇到一个VPN连接问题,分享给大家,看一眼,以后不在这问题上耗费太多功夫. 在win7上连接vpn时抛出“failed to enab ...
- Windows 8 – Reason 442: Failed to enable Virtual Adapter
Cisco VPN on Windows 8.1 – Reason 442: Failed to enable Virtual Adapter https://supertekboy.com/2013 ...
- Composer\Downloader\TransportException ... Failed to enable crypto,failed to open stream: operation failed
failed to open stream: operation failed 错误详细信息: [Composer\Downloader\TransportException] The "h ...
- Foreign key (referential) constraints on DB2 LUW v105
oreign key constraints (also known as referential constraints or referential integrity constraints) ...
- Azure CosmosDB (9) Unique Key Constraints
<Windows Azure Platform 系列文章目录> 在Azure Cosmos DB中,还支持Unique Key Constraints(唯一键约束). 我们可以在Azure ...
- Sqlite: FOREIGN KEY constraint failed on remove的错误原因。
sqlite外键约束中.restrict约束:如果要删除父表,则子表需空. 如果没有定义约束.会报错,需设置一个约束.
随机推荐
- 树莓派 SD卡镜像备份
一.准备工作 1.已经配置启动的树莓派SD卡 2.Linux系统的pc 3.读卡器 二.修改SD卡文件 刚开始我先再win7下把SD卡接到pc上,发现无法读取.用DISKGENIUS查看pc的磁盘状态 ...
- Java使用Itext5.5.10进行pdf签章
说到PDF数字签名签章,这个其实也是数字证书信息安全的应用范畴,关于数字证书和数字签名,网上有很多解释说明,但讲解都多不够详细准确,这边推荐一篇大神的博文,讲解浅显易懂形象数字证书 数字签名 数据加密 ...
- 【Spring】SpringMVC之详解AOP
1,AOP简介 Aspect Oriented Programming 面向切面编程.AOP还是以OOP为基础,只不过将共同逻辑封装为组件,然后通过配置的方式将组件动态切入到原有组件中.这样做的有点 ...
- 【Oracle】Oracle基本数据类型总结
ORACLE基本数据类型(亦叫内置数据类型 built-in datatypes)可以按类型分为:字符串类型.数字类型.日期类型.LOB类型.LONG RAW& RAW类型.ROWID &am ...
- easyui textbox combobox 设置只读不可编辑状态
输入框 textbox $("#xx").textbox('setValue','value'); //设置输入框的值 $('#xx').textbox('textbox').a ...
- C++的字符串格式化库
这里向大家介绍一个C++的字符串格式化库,叫cpptempl,这个库支持对字符串格式的条件,循环,变量插入.看上去很不错,只不过其是基于boost库的. 下面是一个例子: 1 2 3 4 5 6 7 ...
- 【Java】K-means算法Java实现以及图像切割
1.K-means算法简述以及代码原型 数据挖掘中一个重要算法是K-means.我这里就不做具体介绍.假设感兴趣的话能够移步陈皓的博客: http://www.csdn.net/article/201 ...
- java基础知识总结(二)
+=隐含了强制类型转换. x+=y;等价与:x = (x的数据类型)(x + y); 函数重载? 函数名同样.參数列表不同.跟返回值不关,就是函数重载 封装是什么? 隐藏对象的属性和详细的实现细节,仅 ...
- python开发者框架套件总结: package 包 frameworks
python开发者的package 包 框架套件总结: frameworks 开发环境: anaconda pycharm django awesome-django : 介绍 django ...
- JQuery Tree插件——zTree
Demo:点击下载 zTree 在线操作演示:http://www.ztree.me/v3/demo.php#_101