您的位置:首页 > 产品设计 > UI/UE

Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints.

2010-03-04 17:31 429 查看
遇到这个错误 Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints.
document.body.oncopy = function() {
if (window.clipboardData) {
setTimeout(function() {
var text = clipboardData.getData("text");
if (text && text.length > 300) {
text = text + "\r\n\n本文来自CSDN博客,转载请标明出处:" + location.href;
clipboardData.setData("text", text);
}
}, 100);
}
}
function StorePage() { d = document; t = d.selection ? (d.selection.type != 'None' ? d.selection.createRange().text : '') : (d.getSelection ? d.getSelection() : ''); void (keyit = window.open('http://www.365key.com/storeit.aspx?t=' + escape(d.title) + '&u=' + escape(d.location.href) + '&c=' + escape(t), 'keyit', 'scrollbars=no,width=475,height=575,left=75,top=20,status=no,resizable=yes')); keyit.focus(); }

请参考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属性来获得确切的错误信息。

举例如下:

try
{
SqlDataAdapter.Fill(dataTable); //这行会出错,先catch住
}
catch{}

//remove datatable errors
DataRow[] rowsInError;
if (dataTable.HasErrors)
{
// Get an array of all rows with errors.
rowsInError = dataTable.GetErrors();
// Print the error of each column in each row.
StringBuilder sbError = new StringBuilder();
for (int i = 0; i < rowsInError.Length; i++)
{
foreach (DataColumn myCol in dataTable.Columns)
{
sbError.Append(myCol.ColumnName + " " + rowsInError[i].GetColumnError(myCol));
}
// Clear the row errors
rowsInError[i].ClearErrors();
}
}

最后sbError打印出来后就是一堆文字:

{id name title Column 'title' exceeds the MaxLength limit. desc publishdate...}

可以很清楚的看到,是title字段超长了.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐