转换varchar值时转换失败' a'到数据类型int

时间:2016-01-25 20:55:53

标签: sql sql-server entity-framework-5 ssms

我的ADDRESS表的定义肯定有问题。在插入或选择行时,它会将LINE1列视为int,但显然我已将其声明为varchar(128)

此命令正常工作:

insert into address(PERSON_ID, LINE1, TYPE_ID) 
values (234, 'a', 1)

但在SQL Server Management Studio中,当我执行"编辑前200行"并尝试插入相同的值,我收到一条错误消息。

通过SQL查询插入后,从表中选择行会显示相同的错误消息。

通过SSMS编辑行功能或C#插入时以及选择:

时出现的错误消息
  

转换varchar值时转换失败' a'数据类型int。

ADDRESS表:

CREATE TABLE [dbo].[ADDRESS]
(
    [ID] [int] IDENTITY(1,1) NOT NULL,
    [PERSON_ID] [int] NOT NULL,
    [LINE1] [varchar](128) NOT NULL,
    [LINE2] [varchar](128) NULL,
    [CITY] [varchar](256) NULL,
    [COUNTY_ID] [int] NULL,
    [STATE] [int] NULL,
    [POSTAL_CODE] [varchar](16) NULL,
    [COUNTRY_ID] [int] NULL,
    [TYPE_ID] [int] NOT NULL,
    [DESCRIPTION]  AS ([dbo].[GET_ADDRESS_STRING]([ID])),

    CONSTRAINT [PK_ADDRESS] 
       PRIMARY KEY CLUSTERED ([ID] ASC)
           WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, 
                 IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, 
                 ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

0 个答案:

没有答案