使用存储过程获取计数 [英] to get count using stored procedure

查看:124
本文介绍了使用存储过程获取计数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我编写的存储过程

This is stored procedure i written

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



这是我在后面的代码中使用的代码以获取计数,但是计数为0时存储过程中是否有任何修改,请帮助我



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

ObjectParameter count1 = new ObjectParameter("totalCount", typeof(int));
dc.GetTotalJobCount(keyword, count1);
Response.Write(Convert.ToInt32(count1.Value));

推荐答案

按如下所示更改查询.

Change the query as shown.

select @totalCount= count(*)  from Job where ((Title Like '%'+@keyword+'%') or(JobDescription Like '%'+@keyword+'%') or (CompanyName Like '%'+@keyword+'%'))


您需要将数据存储在
@totalcount

输出变量中.

output variable.

select @totalCount = count(*) as COUNTS from Job where ((Title Like '%'+@keyword+'%') or(JobDescription Like '%'+@keyword+'%') or (CompanyName Like '%'+@keyword+'%'))


使用此存储过程,您将获得数据可能只有一列具有名称Counts和一行,因此您必须从数据表中获取它,而不要像这样放置条件

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

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

Response.Write(Convert.ToInt32(dtGetData.Rows[0]["COUNTS"]));


这篇关于使用存储过程获取计数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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