存储过程不起作用 [英] Store proce not working
本文介绍了存储过程不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好
我在sql server 2008中有一个存储过程,当我在服务器资源管理器中执行该存储过程时工作正常,但是当我从程序中调用它时却无法读取任何数据时,这是我的代码:
Hi guys
i have a stored procedure in sql server 2008 which works fine when i execute it in server explorer but when i can''t read any data when i call it from my program,here is my code:
DataTable result = null;
try
{
using (con)
{
using (SqlCommand cmd = con.CreateCommand())
{
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "CheckSite";
cmd.Parameters.Add(new SqlParameter("@site", site));
using (SqlDataAdapter da = new SqlDataAdapter(cmd))
{
result = new DataTable();
da.Fill(result);
if (result.Rows.Count>0)
{
return 1;
}
}
}
}
}
catch (Exception ex)
{
//Pokemon exception handling
}
return 0;
我做错了什么?数据库包含2行!但是我的代码始终返回0(未找到任何内容)
这是我的存储过程:
what did i do wrong?the database contains 2rows!but my code allways returns 0 (as not finding any)
Here it is my store procedure:
ALTER PROCEDURE dbo.CheckSite
@site nvarchar(150)
AS
select sitename from Saved where sitename = @site
RETURN
推荐答案
我认为这是一个字符串问题:
I think it is a problem in this string:
if (result.Rows.Count>0)
尝试在您的过程中设置以下代码:
Try to set following code in your procedure:
SET NOCOUNT OFF;
尝试一下:
try this:
.....
....
...
using (SqlDataAdapter da = new SqlDataAdapter(cmd))
{
DataSet result = new DataSet();
dataset.Tables.Add("aaa");
da.Fill(dataset, "aaa");
if (result.Tables[0].Rows.Count>0)
{
return 1;
}
}
........
.......
这篇关于存储过程不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文