c# - 调用存储过程并检查返回值

标签 c# .net sql sql-server

我有一个名为 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/

相关文章:

c# - 初始化未知类型的通用对象

c# - 我什么时候应该实现 IDisposable?

sql - 当有外键约束时更改主键类型

c# - 将值四舍五入为 .0 或 .5 的数学函数

c# - 在 ASP.NET 中轻松更改日历中的月份和年份

.net - orchard cms 删除/删除内容项

MYSQL SELECT * 不适用于 GROUP BY 和 HAVING

mysql - 在查询中混合使用 ANSI 1992 JOIN 和 COMMA

c# - 将字符串从 memorystream 转换为 binary[] 包含主要废话

c# - C# 中的 ActiveDirectory 入门