Click here to Skip to main content
12,503,334 members (62,002 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C# C#4.0
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:
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:
[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:

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 7-Dec-12 8:37am
Updated 7-Dec-12 8:45am
RaisKazi34.4K
v3
Comments
Zoltán Zörgő 7-Dec-12 15:41pm
   
And what is the exact issue? Any error code?

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

I assume following code need to be replaced:

ExamBusiness.ExamsDataContext db = new ExamBusiness.ExamsDataContext();
 
string recLock = db.spGetLocked(appid, examid).
 
return recLock;

To

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[^]
  Permalink  
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)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160919.1 | Last Updated 7 Dec 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100