Click here to Skip to main content
15,889,867 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello friends.

The below is my store procedure
SQL
create procedure sp_insertclass(@standeredid int,@standeredname varchar(10),@branchname varchar(50) ,@yearfrom smallint,@yearto smallint,@createddatetime datetime)
as
begin
declare @acadamicid int;
declare @branchid int;
select @branchid=Branch_id from Branch where Branch_name=@branchname;
select @acadamicid=Acadamic_year_id from Acadamic_year where Acadamic_year_from=@yearfrom and Acadamic_year_to=@yearto;
insert into Standered_details(Standered_id,Standered_name,Branch_id,Acadamic_year_id,Created_date_time)values(@standeredid,@standeredname,@branchid,@acadamicid,@createddatetime)
end


When executing the above query it succeed.but when insert date through this query the exception occur like Acadamic_year_id is null. but i entered the from year and toyear correctly. please tell me what could be problem in task
One thing i did is yearfrom and yearto variable declared with int datatypes in c# class.Is it make a problem in this place.
Thank in advance
Posted
Updated 27-Jul-12 4:19am
v3

Check whether any academic year is present in the table for the given from date and todate. I think there are no records in the table.


select @acadamicid=Acadamic_year_id from Acadamic_year where Acadamic_year_from=@yearfrom and Acadamic_year_to=@yearto;

If its present, then include begin tran in the starting of stored proc and commit tran after insert
 
Share this answer
 
v2
Comments
baskaran chellasamy 27-Jul-12 10:22am    
yes data present in the table
Santhosh Kumar Jayaraman 27-Jul-12 10:23am    
Can you let us know whats year from, year to value and corresponding academic year id value from db?
Santhosh Kumar Jayaraman 27-Jul-12 10:24am    
ALso include begin tran in the starting of stored proc and commit tran after insert
baskaran chellasamy 27-Jul-12 10:31am    
year from is 2012 and yearto is 2013 and acadamic yearid=112 and one thing i left to mentions is in db yearfrom and yearto is smallint. but in c# class i declared as a int value.if this would be problem mean which datatype need to specify in c#.
Santhosh Kumar Jayaraman 27-Jul-12 10:33am    
just try it with begin tran and commit tran
Not much different to what Solution 1 has to say, but add validation to check for a null value in the @acadamicid parameter, try this:

SQL
if(@acadamicid is not null)
begin

select @acadamicid=Acadamic_year_id from Acadamic_year where Acadamic_year_from=@yearfrom and Acadamic_year_to=@yearto;
insert into Standered_details(Standered_id,Standered_name,Branch_id,Acadamic_year_id,Created_date_time)
values(@standeredid,@standeredname,@branchid,@acadamicid,@createddatetime)
    
end
 
Share this answer
 

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