简体   繁体   English

如何检查存储过程的返回值

[英]How to check for return value from stored procedure

I have a stored procedure that returns a list of numbers in the case that the input id matches the table id. 我有一个存储过程,在输入id与表id匹配的情况下返回一个数字列表。 My question is, how do I check to see if the result being returned from the stored procedure isn't null? 我的问题是,如何检查从存储过程返回的结果是否为空? I just need to know if the returned value is 0(failed) or if the returned values are the numbers. 我只需要知道返回值是0(失败)还是返回值是数字。 Since I have a boolean variable that I want to set if there is valid data returned(not 0). 因为我有一个布尔变量,如果返回有效数据我想设置(不是0)。

Here is my stored procedure: 这是我的存储过程:

      @InvestigatorID int
as
select DeleteTasks
from InvestigatorPermissionsTasks
where InvestigatorID = @InvestigatorID

Valid data returned looks like column name "exhibitID" value "123"/ column name "number" value "1-2-3-2" 返回的有效数据类似于列名“exhibitID”值“123”/列名“number”值“1-2-3-2”

Since you are not using an OUTPUT variable, you will get a recordset returned. 由于您没有使用OUTPUT变量,因此将返回记录集。 If there are no records in the recordset, the query "failed". 如果记录集中没有记录,则查询“失败”。 Otherwise, it was successful and matched at least one record. 否则,它成功并匹配至少一条记录。

You can try with your Filled DataTable 您可以尝试使用填充数据表

var adapter =  new SqlDataAdapter(YourCommand);
DataSet dataSet =  new DataSet();
adapter.Fill(dataSet);
YourTable = dataSet.Tables[0];    
if(YourTable != null)
{
   if(YourTable.Rows.Count > 0)
   { 

   }
}

Link : http://msdn.microsoft.com/fr-fr/library/system.data.common.dataadapter.fill(v=vs.80).aspx 链接: http//msdn.microsoft.com/fr-fr/library/system.data.common.dataadapter.fill(v=vs.80).aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM