I am new to Linq server.
I have a stored procedure in my databse that retuens count number.
select COUNT(*) from tbl_WorkerUsers
where <a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="3c6b534e57594e7f535859017c6b5f535859">[email protected]</a>
when I run it directly in my database it returns 1.
exec checkWorkerCodeAvailibility 100000312
but when I run it in c# code it always returns null.
WorkerDataContext Wkc = new WorkerDataContext();
int? result = Wkc.checkWorkerCodeAvailibility(Int32.Parse(Wcode)).Single().Column1;
what’s wrong?
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
Define your Stored Procedure like this:
CREATE PROCEDURE [dbo].[checkWorkerCodeAvailibility]
@Wcode int = 0
AS
BEGIN
SET NOCOUNT ON;
DECLARE @Result INT
SELECT @Result = COUNT(*) FROM tbl_WorkerUsers WHERE <a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="2e79415c454b5c6d414a4b136e794d414a4b">[email protected]</a>
RETURN @Result
END
You can then access this using the following code:
int result = db.checkWorkerCodeAvailibility(Int32.Parse(WCode));
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0