该列不能包含空值。 SQLCE例外 [英] The column cannot contain null values. SqlCE exception
本文介绍了该列不能包含空值。 SQLCE例外的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我得到了以下异常当我尝试一些样本数据插入到WP7应用程序中的SQL Server CE的3.5数据库:
I'm getting the following exception when I attempt to insert some sample data into a SQL Server CE 3.5 database inside a WP7 application:
错误:SqlCeException的列不能包含空值结果
[列名=名称,表名=考试]
Error: SqlCeException "The column cannot contain null values.
[ Column name = Name,Table name = Exam ]
名称
是主键。我想我已经宣布一切正常在的DataContext
。
The name
is also the primary key. I think I have declared everything properly in the DataContext
.
private void InsertData()
{
mangoDb = new ExamDataContext();
// create a new exam instance
Exam exam = new Exam();
exam.Name = "History";
exam.Description ="History Exam";
// add the new exam to the context
mangoDb.Exams.InsertOnSubmit(exam);
// save changes to the database
mangoDb.SubmitChanges();
}
我在哪里出了错?
推荐答案
我删除表的索引(ES)解决了这个问题。不知道为什么它的工作,但它肯定没有,如果任何人遇到了这个问题。
I solved the problem by deleting the index(es) of The Table. Not sure why it worked, but it certainly did, in case anyone else comes across this issue.
这篇关于该列不能包含空值。 SQLCE例外的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文