Robert Robert - 1 year ago 88
SQL Question

Calling a stored procedure and checking the return value

I have a stored procedure called

and that stored procedure returns a true or false using
ISNULL(@isEqual, 0) as IsProviderSameAsPCP

I am trying to call this stored procedure using a C# method by calling
. But I'm not having any luck - can someone point me in the right direction?

Thanks a lot guys


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

Answer Source

You need to return the value from your stored procedure.

SELECT @isEqual

Aside that you need a SqlConnection object and a SqlCommand object to invoke the stored procedure.

conn = new SqlConnection(connectionString);
SqlCommand cmd  = new SqlCommand("IsProviderSameAsPCP", conn);
cmd.CommandType = CommandType.StoredProcedure;
rdr = cmd.ExecuteReader();

You can then use the rdr object to loop through the result set.

You can find your connection string at:

I.e. for SQL Server 2008:

string connectionString = "Server=myServerAddress;Database=myDataBase;Trusted_Connection=True;";
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download