简体   繁体   English

Visual Studio项目错误

[英]Visual Studio project error

This is my table as shown in image 这是我的表格,如图所示

在此输入图像描述

This is my stored procedure for insert 这是我的插入存储过程

在此输入图像描述

but when I am trying to execute it with my project project shows error as below. 但是当我试图用我的项目项目执行它时显示如下错误。

ERROR: 错误:

Cannot insert the value NULL into column 'SID', table 'AttDemo.dbo.StdMst'; 无法将值NULL插入列'SID',表'AttDemo.dbo.StdMst'; column does not allow nulls. 列不允许空值。 INSERT fails. INSERT失败。
The statement has been terminated. 该语句已终止。

The easiest way to fix this would be to set the primary key to autoincrement / as an Identity. 解决此问题的最简单方法是将主键设置为自动增量/作为标识。

Alternatively, you could change This: 或者,你可以改变这个:

GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[STDMST_INSERT]

    @STDNAME AS NVARCHAR (50)
AS
BEGIN

    INSERT INTO (StdMst (StdName, EDate) VALUES(@STDNAME, GETDATE())

END
GO

To this: 对此:

GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[STDMST_INSERT]

    @STDNAME AS NVARCHAR (50)
AS
BEGIN

    INSERT INTO (StdMst (SID, StdName, EDate) VALUES(IDENT_CURRENT('StdMst'), @STDNAME, GETDATE())

END
GO

The issue you are having is that your primary key does not allow NULL values and is not set to autoincrement. 您遇到的问题是您的主键不允许NULL值,并且未设置为自动增量。

Here are some useful links: 以下是一些有用的链接:

Set Primary Key as Identity 将主键设置为标识
Setting key to autoincrement 设置自动增量的关键

看起来您认为您的SID列是IDENTITY列,但事实并非如此。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM