Click here to Skip to main content
15,893,588 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
A c# solution with 3 projects:
1. linq-to-sql Business Layer.
2. Web Service layer.
3. Normal proxy, web consumer fromnt end with all my UI.

Problem:
I cannot get an nvarchar value from my stored procedure that I can use in the code.

The Procedure:
SQL
ALTER PROCEDURE [dbo].[spGetLocked]
	-- Add the parameters for the stored procedure here
	@appid varchar(10),
	@examcode varchar(10)
AS

BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	SELECT record_lock 
	FROM user_result
	WHERE appid = @appid and exam_id = @examcode
	
	RETURN
	
END

The code built in the designer:
C#
[global::System.Data.Linq.Mapping.FunctionAttribute(Name="dbo.spGetLocked")]
		public ISingleResult<spgetlockedresult> spGetLocked([global::System.Data.Linq.Mapping.ParameterAttribute(DbType="VarChar(10)")] string appid, [global::System.Data.Linq.Mapping.ParameterAttribute(DbType="VarChar(10)")] string examcode)
		{
			IExecuteResult result = this.ExecuteMethodCall(this, ((MethodInfo)(MethodInfo.GetCurrentMethod())), appid, examcode);
			return ((ISingleResult<spgetlockedresult>)(result.ReturnValue));
		}

My attempt at calling the procedure:

C#
ExamBusiness.ExamsDataContext db = new ExamBusiness.ExamsDataContext();

string recLock = db.spGetLocked(appid, examid).

return recLock;


I am trying to get the value of field record_lock (T or F) nvarchar(1) for a business decision in my check_login code.

Please help, I have been stuck for 10 straight hours.

Thank you,
Suzanne
Posted
Updated 7-Dec-12 8:45am
v3
Comments
Zoltán Zörgő 7-Dec-12 15:41pm    
And what is the exact issue? Any error code?

1 solution

I assume following code need to be replaced:

VB
ExamBusiness.ExamsDataContext db = new ExamBusiness.ExamsDataContext();

string recLock = db.spGetLocked(appid, examid).

return recLock;


To

VB
ExamBusiness.ExamsDataContext db = new ExamBusiness.ExamsDataContext();

ISingleResult<spgetlockedresult> result = db.spGetLocked(appid, examid);

//Check result.FirstOrDefault for not null 
string recLock = result.FirstOrDefault().record_lock; 

return recLock;</spgetlockedresult>



Please refer http://msdn.microsoft.com/en-us/library/bb534556.aspx[^]
 
Share this answer
 
Comments
Suzanne Jarrett 7-Dec-12 16:07pm    
Thank you,
I will try it right now.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900