Click here to Skip to main content
15,893,161 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
This is stored procedure i written
SQL
ALTER procedure [dbo].[GetTotalJobCount]
(

@keyword varchar(50),
@totalCount int OUT
)
as begin
select count(*) as COUNTS from Job where ((Title Like '%'+@keyword+'%') or(JobDescription Like '%'+@keyword+'%') or (CompanyName Like '%'+@keyword+'%'))
end


This is the code i use in code behind to get the count but am getting 0 count is there any modifications in stored procedure please help me

C#
ObjectParameter count1 = new ObjectParameter("totalCount", typeof(int));
dc.GetTotalJobCount(keyword, count1);
Response.Write(Convert.ToInt32(count1.Value));
Posted
Updated 8-Jun-14 20:53pm
v2
Comments
Sunasara Imdadhusen 9-Jun-14 2:55am    
Please use @totalCount= count(*) in your select query. See Arun's answer below.

Change the query as shown.

SQL
select @totalCount= count(*)  from Job where ((Title Like '%'+@keyword+'%') or(JobDescription Like '%'+@keyword+'%') or (CompanyName Like '%'+@keyword+'%'))
 
Share this answer
 
Comments
Sunasara Imdadhusen 9-Jun-14 2:55am    
Correct answer Arun. my vote 5.
Member 10226004 9-Jun-14 3:01am    
i had written same as above but when i importing function to stored procedure am facing issue if i select complex type for creating function to stored procedure am getting the coulmn as Column1 when am running it showing that mistach of column how to rectify that
you need store data in
SQL
@totalcount
output variable.

SQL
select @totalCount = count(*) as COUNTS from Job where ((Title Like '%'+@keyword+'%') or(JobDescription Like '%'+@keyword+'%') or (CompanyName Like '%'+@keyword+'%'))
 
Share this answer
 
with this stored procedure you will get datatable having one column having name Counts and one row ,so you have to take it from datatable and than put condition regarding that like that

C#
DataTable dtGetData = new DataTable();
dtGetData = GetTotalJobCount(keyword); //Create Function for fill datatable from stored procedure

Response.Write(Convert.ToInt32(dtGetData.Rows[0]["COUNTS"]));
 
Share this answer
 
v2

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