我正在尝试将新记录保存到我的sql服务器数据库中。但是我不断收到这个错误
System.FormatException:输入字符串的格式不正确。在MOH处System.Int32.Parse(String s)处System.Number.ParseInt32(String s,NumberStyles style,NumberFormatInfo info)在System.Number.StringToNumber(String str,NumberStyles选项,NumberBuffer&number,NumberFormatInfo info,Boolean parseDecimal) .SID'......'CauseOfDeath.aspx.cs:第206行
我尝试检查数据库和模型的数据类型兼容性,但似乎一切都匹配。
DateTime DOBdate = Convert.ToDateTime(txtDOB.Text); DateTime DODdate = Convert.ToDateTime(txtDOD.Text);
DateTime DLSDate = Convert.ToDateTime(txtDLS.Text);
DateTime DOCDate = Convert.ToDateTime(txtDOC.Text);
try
{
Databases.COD cod = new Databases.COD()
{
Facility = ddlFacility.SelectedValue.ToString(),
Nationality = ddlNationality.Text,
PIN = int.Parse(txtPIN.Text),
LastName = txtLastName.Text,
FirstName = txtLastName.Text,
MiddleName = txtMiddleName.Text,
DOB = Convert.ToString(DOBdate),
DOD = Convert.ToString(DODdate),
Type_Of_PL = ddlTOPOD.Text,
POUR_Inkhundla = ddlInkhundla1.Text,
POUR_Locality = ddlChiefdom1.Text,
POPR_Inkhundla = ddlInkhundla2.Text,
POPR_Locality = ddlChiefdom2.Text,
MOD = ddlMOD.Text,
Maternal_Death = ddlMotherPregnancyStatus.Text,
Maternal_Death_Within42dys = ddlWithin42.Text,
DLS = Convert.ToString(DLSDate),
TOC = ddltypeOfCertification.Text,
Practice_Number = txtPracticeNumber.Text,
NOC = txtNameOfCertifier.Text,
DOC = Convert.ToString(DOCDate),
Condition_Leading = txtcondition1.Text,
Condition_Leading_Period = int.Parse(TxtCondition1Period.Text),
Condition_Leading_ICD_Code = txtCondition1ICDCode.Text,
Antecedent1 = txtAntecedent.Text,
Antecedent_Period = int.Parse(txtAntecedentPeriod.Text),
Antecedent_ICD_Code = txtAntecedentICDCode.Text,
Antecedent2 = txtAntecedent1.Text,
Antecedent2_Period = int.Parse(txtAntecedent1Period.Text),
Antecedent2_ICD_Code = txtAntecedent1Period.Text,
Antecedent3 = txtAntecedent2.Text,
Antecedent3_Period = int.Parse(txtAntecedent2Period.Text),
Antecedent3_ICD_Code = txtAntecedent2ICDCode.Text,
Other_Condition = txtotherconditions.Text,
Otehr_Condition_ICD_Code = txtOtherICD.Text,
};
healthDC.CODs.Add(cod);
我需要将这些值保存到我的表中。
CREATE TABLE [dbo].[COD](
[ID] [varchar](10) NOT NULL,
[Facility] [varchar](50) NULL,
[Nationality] [varchar](20) NULL,
[PIN] [int] NULL,
[LastName] [varchar](15) NULL,
[FirstName] [varchar](15) NULL,
[MiddleName] [varchar](10) NULL,
[DOB] [varchar](50) NULL,
[DOD] [varchar](50) NULL,
[Type_Of_PL] [varchar](50) NULL,
[POUR_Locality] [varchar](50) NULL,
[POUR_Inkhundla] [varchar](50) NULL,
[POPR_Locality] [varchar](50) NULL,
[POPR_Inkhundla] [varchar](50) NULL,
[MOD] [varchar](25) NULL,
[Maternal_Death] [varchar](3) NULL,
[Maternal_Death_Within42dys] [varchar](3) NULL,
[DLS] [varchar](50) NULL,
[TOC] [varchar](50) NULL,
[Practice_Number] [varchar](25) NULL,
[NOC] [varchar](50) NULL,
[DOC] [varchar](50) NULL,
[Condition_Leading] [varchar](50) NULL,
[Condition_Leading_Period] [int] NULL,
[Condition_Leading_ICD_Code] [varchar](10) NULL,
[Antecedent1] [varchar](50) NULL,
[Antecedent_Period] [int] NULL,
[Antecedent_ICD_Code] [varchar](10) NULL,
[Antecedent2] [varchar](50) NULL,
[Antecedent2_Period] [int] NULL,
[Antecedent2_ICD_Code] [varchar](10) NULL,
[Antecedent3] [varchar](50) NULL,
[Antecedent3_Period] [int] NULL,
[Antecedent3_ICD_Code] [varchar](10) NULL,
[Other_Condition] [varchar](50) NULL,
[Otehr_Condition_ICD_Code] [varchar](10) NULL,