如何使用Storeprocedure插入记录.. [英] How Do I Insert Record By Using Storeprocedure..

查看:81
本文介绍了如何使用Storeprocedure插入记录..的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里我有一个名为

Student_Images(id int identity(100,2),ImageName varchar(50),Imagepath varchar(100),Imageblob image)



这是我的商店程序


Here is my store procedure

ALTER procedure [dbo].[getStudentImagessp](
@ImageName varchar(50),
@Imagepath varchar(100),
@Imageblob image,
@type nvarchar(3)
)
as begin 
if(@type='i')
begin
insert into [Student_Images](ImageName,Imagepath,Imageblob) values(@ImageName,@Imagepath,@Imageblob)
end
end



我发送g来自前端的 @ ImageName,@ Imagepath,@ Imageblob,@ type 的参数..但我得到的异常是什么无法将值NULL插入列'Id',表中; 'kavali.dbo.Student_Images';列不允许空值。 INSERT失败。

声明已被终止。

..实际上我的表中没有记录,我打算插入我的第一个记录,但为什么我得到一个例外,要求无法将Null值插入列'Id' ...这里我不会试图插入空值实际上我没有从前面传递任何值到我的标识列结束...请给我任何建议.....


I am sending parameters of @ImageName,@Imagepath,@Imageblob,@type from frond end..but what the exception i was getting is Cannot insert the value NULL into column 'Id', table;'kavali.dbo.Student_Images'; column does not allow nulls. INSERT fails.
The statement has been terminated.
..Actually there is no records present in my table, I was going to make my first record inserting, but why i was getting an exception of asking cannot insert Null values in to column 'Id'...here i m not triying to insert null values actually i m not passing any values to my identity column from front end...is there any suggestion for me please.....

推荐答案

你需要设置它,否则如果你有一个不可为空的列,没有默认值,如果你没有提供任何值就会出错。



在SQL Server Management Studio中设置自动增量:



1)在设计中打开你的桌子

2)选择你的专栏并转到栏目属性

3)在Indentity Specification下,设置(是身份)=是和身份增量= 1



参考.. :)



为什么SQL服务器抛出此错误:无法将值NULL插入列'id '? [ ^ ]
You need to set this, or else if you have a non-nullable column, with no default value, if you provide no value it will error.

To set up auto-increment in SQL Server Management Studio:

1) Open your table in Design
2) Select your column and go to Column Properties
3) Under Indentity Specification, set (Is Identity)=Yes and Indentity Increment=1

References.. :)

Why is SQL server throwing this error: Cannot insert the value NULL into column 'id'?[^]


这篇关于如何使用Storeprocedure插入记录..的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆