My function isn’t returning anything – strReturn is empty:
try
{
SqlParameter[] parameter = new SqlParameter[]
{
new SqlParameter("@MerchantID", MercahntID),
new SqlParameter("@LoactionID", LoactionID)
};
SqlHelper.ExecuteNonQuery(DbConnString, System.Data.CommandType.StoredProcedure, "GetMerchantLocationZip", parameter);
return strReturn;
}
catch (Exception ex)
{
LogError("Error Occurred When Retrieving Mercahnt Location Zip: MercahntID:" + MercahntID.ToString(), ex);
return strReturn;
}
}
When I execute this stored proc using ‘exec GetMerchantLocationZip (3333, 373773)’ I get the correct zipcode in SQL. Why don’t I get it in Visual Studio?
Create PROCEDURE [dbo].[GetMerchantLocationZip](
@MerchantID bigint,
@LoactionID bigint)
AS
Begin
Select Zip FROM Merchant_Location
where MerchantID=@MerchantID AND LocationID =@LoactionID
End
I am learning, so apologies if it’s a obvious error. Thanks all!
You’re not getting results because you’re not executing the code as a Query.
You’re calling
SqlHelper.ExecuteNonQuery()which doesn’t return any results.It looks like you’re using the SqlHelper application block, so I think the code you want would be (if you’re returning multiple rows in the query):
dswill then contain the results of the query.If you’re trying to retrieve a single value from the database rather than a set of rows, then your code would be: