0

I am new to Linq server. I have a stored procedure in my databse that retuens count number.

select COUNT(*) from tbl_WorkerUsers 
        where WorkerCode=@Wcode

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?

Drew
  • 29,895
  • 7
  • 74
  • 104
Raymond Morphy
  • 2,464
  • 9
  • 51
  • 93
  • Add a breakpoint at Wkc.checkWorkerCodeAvailibility(Int32.Parse(Wcode)).Single().Column1; and check the value of Wcode variable also check the profiler, that might give you a clue – Nasmi Sabeer Mar 31 '11 at 09:46

1 Answers1

6

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 WorkerCode=@Wcode
    RETURN @Result
END

You can then access this using the following code:

int result = db.checkWorkerCodeAvailibility(Int32.Parse(WCode));
Druid
  • 6,423
  • 4
  • 41
  • 56