2013-06-24 45 views
2

我有一个存储过程称为pat_selectPatientById和真或假的使用ISNULL(@isEqual, 0) as IsProviderSameAsPCP该存储过程返回。调用存储过程和检查返回值

我试图通过调用Application.WebService.ExecuteQuery("pat_selectPatientById")调用使用C#方法,此存储过程。但我没有任何运气 - 有人能指引我走向正确的方向吗?

非常感谢球员

代码:

declare @isEqual bit = 
    (select 
     top 1 1 as IsEqual 
    from 
     Patient p 
    inner join 
     [Resource] r on p.ProviderId = r.ResourceId 
    where 
     PatientId = @PatientId 
     and p.PrimaryCareProviderId = r.RefPhysId) 
+0

是否有您所使用的框架法的ExecuteScalar? –

+0

没有没有 – Robert

+0

您可以使用自定义代码还是必须通过这个方法,你所提到的,即Application.WebService ..? –

回答

3

你需要从存储过程返回值。

SELECT @isEqual 

除此之外,你需要一个SqlConnection对象和SqlCommand对象调用存储过程。可以使用rdr对象循环遍历结果集。

您可以在您的连接字符串:

http://www.connectionstrings.com/

即对于SQL Server 2008

string connectionString = "Server=myServerAddress;Database=myDataBase;Trusted_Connection=True;"; 
+0

感谢这工作! – Robert

2

您需要在select返回值。在PROC下一行需要是

select @isEqual 

即.. 声明@isEqual位= (选择 顶部11从 患者P内加入[资源] R 上ISEQUAL p.ProviderId = r.ResourceId 其中 PatientId = @PatientId 和p.PrimaryCareProviderId = r.RefPhysId) 选择@isEqual

的ExecuteScalar在C#中,你正在寻找的命令。如果您有多个值并且不想返回表输出,您也可以在存储过程中使用输出参数。