我现在遇到了麻烦,我无法在 DBDataContext 中更新表 X,所以这是我的片段,顺便说一下,当我只更新一个表时它可以工作!但是当我插入然后更新时,它会抛出异常:“无法将对象从 System.Int32 转换为 System.String 类型”
{
using (DBDataContext db = new DBDataContext())
{
int codigo = Convert.ToInt32(lblNroInforme.Content);
int sucessfull = 0;
INFORMEMEDICO varInf = (from i in db.INFORMEMEDICOs
where i.numeroinforme == codigo
select i).SingleOrDefault();
if (varInf == null)
{
varInf = new INFORMEMEDICO();
varInf.codigoclase = Convert.ToInt32(lblCodigoClase.Content.ToString());
varInf.codigoestudio = lblCodigoEstudio.Content.ToString();
varInf.codigopaciente = Convert.ToInt32(lblCodigoPaciente.Content.ToString());
varInf.conclusion = GetText(rtbConclusion);
varInf.fechainforme = DateTime.Today;
varInf.firmauno = getJPGFromImageControl(firmaUno.Source as BitmapImage);
varInf.firmados = getJPGFromImageControl(firmaDos.Source as BitmapImage);
varInf.hallazgo = GetText(rtbHallazgo);
varInf.horainforme = Convert.ToDateTime(DateTime.Today.ToShortTimeString());
varInf.impreso = 0;
varInf.medicoinforma = cboTurnoMed.SelectedValue.ToString();
varInf.nombreinforme = txtNombreExamen.Text;
varInf.numeroinforme = Convert.ToInt32(lblNroInforme.Content.ToString());
varInf.tecnica = GetText(rtbTecnica);
varInf.turnosocio = lblTurnoMedico.Content.ToString();
try
{
db.INFORMEMEDICOs.InsertOnSubmit(varInf);
db.SubmitChanges();
sucessfull = 1;
}
catch (Exception ex)
{
MessageBox.Show("Error : " + ex.Message);
}
if (sucessfull==1)
{
EXAMENXATENCION varExA = (from ea in db.EXAMENXATENCIONs
where ea.codigo == codigo
select ea).SingleOrDefault();
varExA.estadoestudio = 'I';
db.SubmitChanges();
}
}
}
}
当我执行更新时,我从调试器中获取了这个堆栈:
en System.Data.Linq.IdentityManager.StandardIdentityManager.MultiKeyManager`3.TryCreateKeyFromValues(Object[] values, MultiKey`2& k)
en System.Data.Linq.IdentityManager.StandardIdentityManager.MultiKeyManager`3.TryCreateKeyFromValues(Object[] values, MultiKey`2& k)
en System.Data.Linq.IdentityManager.StandardIdentityManager.MultiKeyManager`3.TryCreateKeyFromValues(Object[] values, MultiKey`2& k)
en System.Data.Linq.IdentityManager.StandardIdentityManager.MultiKeyManager`3.TryCreateKeyFromValues(Object[] values, MultiKey`2& k)
en System.Data.Linq.IdentityManager.StandardIdentityManager.IdentityCache`2.Find(Object[] keyValues)
en System.Data.Linq.IdentityManager.StandardIdentityManager.Find(MetaType type, Object[] keyValues)
en System.Data.Linq.CommonDataServices.GetCachedObject(MetaType type, Object[] keyValues)
en System.Data.Linq.ChangeProcessor.GetOtherItem(MetaAssociation assoc, Object instance)
en System.Data.Linq.ChangeProcessor.BuildEdgeMaps()
en System.Data.Linq.ChangeProcessor.SubmitChanges(ConflictMode failureMode)
en System.Data.Linq.DataContext.SubmitChanges(ConflictMode failureMode)
en System.Data.Linq.DataContext.SubmitChanges()
en Demo.View.InformeMedico.btnGuardar_Click(Object sender, RoutedEventArgs e) en D:\cs_InformeMedico\app\InformeMedico.xaml.cs:línea 430