...isnt Null is whats coming in from the application (DBNull)?
No. You sent NULL to the stored procedure (as @pProjId). In the SP you have
if @pProjId = null
begin
insert into hip_Project (ProjectName, ProjectDesc, ProjectNotes, dtCreated)
values (@pProjName, @pProjDesc, @pProjNotes, @pProjDate)
end
else
...
which means that if @pProjId is NULL then SP will insert new entry into the hip_Project table.
As we can see, there is no value specified for the Project_Id column, which means that
either this column should accept NULL
or it should be an identity column that is made up of values generated by the database.
Now, see the code below
if @pProjId = null
SELECT SCOPE_IDENTITY() as newProjectID
else
...
This tells me that it is expected to get a value from the SCOPE_IDENTITY function which returns the last identity value inserted into an identity column in the same scope. As there is only one INSERT statement - it means that the the Project_Id column should
be an identity column and not NULL.
smirnov
All-Star
23694 Points
4053 Posts
Re: Object cannot be cast from DBNull to other types
Oct 18, 2010 06:41 AM|LINK
No. You sent NULL to the stored procedure (as @pProjId). In the SP you have
if @pProjId = null begin insert into hip_Project (ProjectName, ProjectDesc, ProjectNotes, dtCreated) values (@pProjName, @pProjDesc, @pProjNotes, @pProjDate) end else ...which means that if @pProjId is NULL then SP will insert new entry into the hip_Project table.
As we can see, there is no value specified for the Project_Id column, which means that
Now, see the code below
if @pProjId = null SELECT SCOPE_IDENTITY() as newProjectID else ...This tells me that it is expected to get a value from the SCOPE_IDENTITY function which returns the last identity value inserted into an identity column in the same scope. As there is only one INSERT statement - it means that the the Project_Id column should be an identity column and not NULL.