Click here to Skip to main content
15,893,564 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Here I have a table of name
C#
Student_Images(id int identity(100,2),ImageName varchar(50),Imagepath varchar(100),Imageblob image)

Here is my store procedure
C#
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

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.....
Posted
Comments
Murali Vijay 16-Jun-14 3:14am    
everything works fine what you have tried in my local also.Go and check whether identity is set or not for column id in your database
Naveen Kumar Malli 16-Jun-14 4:41am    
Thank you for suggestion, every thing is fine now....i have again created a new table of same fields..it's working now ..but the thing is i had followed the same steps as before..but it is working now...why it wasn't earlier....
TrushnaK 16-Jun-14 3:45am    
is your id column is auto increamented..
If not then you have to pass value for that (I consider that id column has primary key).
Naveen Kumar Malli 16-Jun-14 4:41am    
Thank you for suggestion, every thing is fine now....i have again created a new table of same fields..it's working now ..but the thing is i had followed the same steps as before..but it is working now...why it wasn't earlier....

1 solution

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'?[^]
 
Share this answer
 
Comments
Naveen Kumar Malli 16-Jun-14 4:41am    
Thank you for suggestion, every thing is fine now....i have again created a new table of same fields..it's working now ..but the thing is i had followed the same steps as before..but it is working now...why it wasn't earlier....

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900