我有一个名为 pat_selectPatientById
的存储过程,该存储过程使用 ISNULL(@isEqual, 0) 作为 IsProviderSameAsPCP
返回 true 或 false。
我尝试通过调用 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)
最佳答案
您需要从存储过程返回值。
SELECT @isEqual
除此之外,您还需要一个 SqlConnection
对象和一个 SqlCommand
对象来调用存储过程。
conn = new SqlConnection(connectionString);
conn.Open();
SqlCommand cmd = new SqlCommand("IsProviderSameAsPCP", conn);
cmd.CommandType = CommandType.StoredProcedure;
rdr = cmd.ExecuteReader();
然后您可以使用 rdr
对象循环访问结果集。
您可以在以下位置找到您的连接字符串:
http://www.connectionstrings.com/
即对于SQL Server 2008
:
string connectionString = "Server=myServerAddress;Database=myDataBase;Trusted_Connection=True;";
关于c# - 调用存储过程并检查返回值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17276570/