System.Data.dll中发生未处理的“System.OverflowException”类型异常。算术运算导致溢出

时间:2015-10-21 22:04:50

标签: c# sql-server system.data

我突然开始在多个C#项目中出现以下错误仅在我的电脑上

  

System.Data.dll中发生了未处理的“System.OverflowException”类型异常   附加信息:算术运算导致溢出。

我试图用.Net framework 4运行我的项目,然后是3.5,3和4.5,但总是一样的错误。在处理我的SQL Server数据库时,在项目中使用dataadapter和其他项目在尝试打开连接时填充数据表时,总会出现错误。这是一个示例代码:

        string strConn = "Data Source=Home\\SqlExpress;Initial Catalog=PatientDBNew;Integrated Security=True";
        SqlConnection conn = new SqlConnection(strConn);
        string sql = string.Format("Select 'file:///' + FolderPath + PhotoName As PhotoPath From Patient Inner Join Photo On Patient.FileNumber = Photo.FileNumber Where Patient.FileNumber = '{0}' And BeforeOrAfter = {1} Order by DateTimeAdded Asc", Patient.FileNumber, beforeOrAfter);
        SqlDataAdapter da = new SqlDataAdapter(sql, conn); ;
        DataTable dt = null;

        try
        {
            dt = new DataTable();
            da.Fill(dt); //**here I get the exception**
        }
        catch (Exception ex)
        {
            ErrorLog("MethodName", ex);
        }

这是来自另一个项目:

        string strConn = "Data Source=Home\\SqlExpress;Initial Catalog=PatientDB;Integrated Security=True";
        SqlConnection conn = new SqlConnection(strConn);
        string sql = string.Format("Select Replace([Filenumber], 'A', '20'), [Bphoto_issuing_date], [Aphoto_issuing_date] From [Patient_Master] Where FileNumber like 'A%' Order by FileNumber");
        SqlDataAdapter da = new SqlDataAdapter(sql, conn);
        DataTable dt = new DataTable();
        da.Fill(dt); //**Here I don't get an exception!**

        strConn = "Data Source=MSD-Home;Initial Catalog=PatientDBNew;Integrated Security=True";
        conn = new SqlConnection(strConn);

        foreach (DataRow item in dt.Rows)
        {
            string fileNb = item[0].ToString();
            string startOfTreatment = item[1].ToString();
            string endOfTreatment = item[2].ToString();

            sql = "Update Patient Set BPhotoDate = '" + startOfTreatment + "', APhotoDate = '" + endOfTreatment + "' Where FileNumber = '" + fileNb + "'";

            using (SqlCommand cmd = new SqlCommand(sql))
            {
                cmd.Connection = conn;
                conn.Open(); //**Here I get the exception**
                cmd.ExecuteNonQuery();
                conn.Close();
            }
        }

显而易见的是,在处理PatientDB时,它的进展顺利,而在使用PatientDBNew的情况下则不然。我试图弄清楚问题是什么,但不能。这是PatientDBNew数据库中的“Patient”结构表:

SET ANSI_PADDING ON
GO

CREATE TABLE [dbo].[Patient](
    [FileNumber] [varchar](25) NOT NULL,
    [PhysicianId] [int] NOT NULL,
    [FolderPath] [varchar](MAX) NULL CONSTRAINT [DF_Patient_FolderPath]  DEFAULT (''),
    [BPhotoDate] [datetime] NULL,
    [APhotoDate] [datetime] NULL,
 CONSTRAINT [PK_Patient] PRIMARY KEY CLUSTERED 
(
    [FileNumber] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

GO

SET ANSI_PADDING OFF
GO

ALTER TABLE [dbo].[Patient]  WITH CHECK ADD  CONSTRAINT [FK_Patient_Physician] FOREIGN KEY([PhysicianId])
REFERENCES [dbo].[Physician] ([PhysicianId])
GO

ALTER TABLE [dbo].[Patient] CHECK CONSTRAINT [FK_Patient_Physician]
GO

FilenNumber不超过25个字符,PhysicianId总是1或2,正如我之前所说的那样,直到2天前我才开始出现此错误,但没有任何异常。

0 个答案:

没有答案