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约束:如果要删除父表,则子表需空. 如果没有定义约束.会报错,需设置一个约束.
随机推荐
- ROS学习(十二)—— 编写简单的消息发布器和订阅器(C++)
一.创建发布器节点 1 节点功能: 不断的在ROS网络中广播消息 2 创建节点 (1)打开工作空间目录 cd ~/catkin_ws/src/beginner_tutorials 创建一个发布器节点( ...
- Python学习笔记(十一)—— 函数式编程
一.函数式编程理念 函数式编程就是一种抽象程度很高的编程范式,纯粹的函数式编程语言编写的函数没有变量,因此,任意一个函数,只要输入是确定的,输出就是确定的,这种纯函数我们称之为没有副作用.而允许使用变 ...
- ANDROID开机动画分析
开机动画文件:bootanimation.zip在system\media文件夹下动画是由系列图片连续刷屏实现的..bootanimation.zip文件是zip压缩文件,压缩方式要求是存储压缩,包含 ...
- 去掉WinLicense文件效验的方法
去掉WinLicense文件效验的方法 --------------Breakpoints-------------- 地址 模块 活动 反汇编 注释------------------------- ...
- Java NIO.2 —— 文件或目录移动操作
移动文件树是复制和删除的文件树的结合.实际上,有两种方式来完成文件的移动.一种是使用Files.move(), Files.copy(), 和Files.delete() 这三个方法:另一种是只使用F ...
- 实战Apache+Tomcat集群和负载均衡
实战Apache+Tomcat集群和负载均衡 目录 1. 什么是J2EE集群... 3 1.1. 序言... 3 1.2. 基本术语... 3 伸缩性(Scalability): ...
- SNF微信公众号客户端演示-微信开发客户端能干什么
关注测试微信号: 关注后菜单页面如下: 一.扫描二维码进行订单查询演示 1.点击菜单“软件产品”->选择“扫描查询” 2.扫描如下二维码进行订单查询演示. 3.扫描结果如下: 二.微信“输入订单 ...
- lnmp 一键安装
系统需求: CentOS/RHEL/Fedora/Debian/Ubuntu/Raspbian/Deepin Server/Aliyun/Amazon/Mint Linux发行版 需要5GB以上硬盘剩 ...
- AndroidStudio创建项目时一直处于building“project name”gradle project info的解决办法
AndroidStudio创建项目,最后一步finish后,一直长时间处于building“project name”gradle project info,界面就一直停留在如图所示: 谷歌自家的产品 ...
- Jenkins管理静态资源
这里我们的前端是使用webpack来管理静态资源的,把静态资源上传到svn上面来管理 这里我们把项目和静态资源剥离开来,然后静态资源接入CDN 我们的svn的结构是这样的 我们需要把这些目录都进行打包 ...