0
我目前在我的项目中遇到问题。我在Silverlight应用程序中遇到了代码4004错误。我不知道我做错了什么。这里是图片链接。C#silverlight应用程序中的代码4004
http://s1100.photobucket.com/user/Fredi_Tansari/media/errorInsilverlight.png.html
这里的代码。在invalideoperation异常之后,它进入未处理的异常错误。提前
private void getstatusCompleted(LoadOperation<PatientStatus1> obj)
{
try
{
PatientStatus1 bc = obj.Entities.First();
if (bc != null)
{
MessageBox.Show("Patient has a status already, please use update instead new");
return;
}
else
{
MessageBox.Show("inserting new Patient status");
}
}
catch (InvalidOperationException e)
{
PatientStatus1 newPatientStatus = new PatientStatus1();
newPatientStatus.ColorCodeID = "1";
newPatientStatus.timestamp = DateTime.Now;
newPatientStatus.UserID = "Jimmi";
newPatientStatus.Patient_PatientID = Convert.ToInt32(patientIDTextBox.Text);
newPatientStatus.MasterPatientStatus_masterPatientStatusId = Convert.ToInt32(masterPatientStatusIdTextBox.Text);
newPatientStatus.MasterLocation_masterLocationID = Convert.ToInt32(masterLocationIDTextBox1.Text);
patientstatusDomainContext.PatientStatus1s.Add(newPatientStatus);
patientstatusDomainContext.SubmitChanges();
}
}
感谢您的帮助
你为什么把对象创建代码在你的catch-block?你难道不能防止发生无效的操作而忽略它吗?哪一行代码会导致下一个异常? – Terry
你好,Djerry,在patientdomaincontext.submitchanges();我现在非常难过。我只想检查数据库中是否已存在数据,当我决定使用try-catch时,请随时提供更好的方法来实现它。 –
我想你正在使用实体框架,所以我不会建议工作方法,因为我不熟悉。你现在可以做的就是在产生错误的线上放一个try-catch(你可以在找到导致这个错误的东西时去掉这个try catch)。 SL的错误有时会让人困惑,所以请看看错误告诉你什么。 – Terry