Solved

storing records in temp table in sql server and using LINQ in C# to access these records

Posted on 2011-09-09
6
362 Views
Last Modified: 2013-11-11
I am using LINQ with c# and pulling certain questions (say 25) from a table randomly and need to store these questions some where in database say in a temp table. Now on every next or previous button clicks I need records from this temp table. On finish button click i need to drop this table. I created one stored procedure, used select into statement and filled this temp table. Second stored procedure to pull the values from this sp but I got an error reading through this stored procedure. Any ideas how can we fix the following error or is there better way of dealing this issue

Error: Stored procedure returning integer instead of ISingleResult


I also tried creating a table variable as mentioned on this site http://odetocode.com/code/365.aspx  but I can't access this Table variable in other stored procedures on next previous clicks

Any ideas
0
Comment
Question by:mmalik15
  • 3
  • 2
6 Comments
 
LVL 63

Expert Comment

by:Fernando Soto
ID: 36510812

Can you post the Stored Procedure.
0
 

Author Comment

by:mmalik15
ID: 36513409
sure following is my sp
ALTER PROCEDURE [dbo].[sp_GetRandomQuestionsAndStoreInTempTable]
	-- Add the parameters for the stored procedure here
	@QuizID varchar(500)
	
AS
BEGIN
	
Create table #UserQuestionstmp 
(
QuestionID int,
Question varchar(8000),
Choices varchar(8000),
CorrectAnswer varchar(5000),
RelatedInfo varchar(8000),
QuestionType varchar(50),
Section varchar(5000),
QuestionNo int
)

INSERT INTO #UserQuestionstmp
exec dbo.sp_GetQuestionsByChapterID @QuizID



END

Open in new window

0
 

Author Comment

by:mmalik15
ID: 36513425
And the error I am getting is

The return types for the following stored procedures could not be detected. Set the return type for each stored procedure in the Properties window.
0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
LVL 63

Expert Comment

by:Fernando Soto
ID: 36514983

Are you sure that this is the correct SP. I am not a SQL Guru but it looks like to be it creates a table and insert record into it?
0
 

Author Comment

by:mmalik15
ID: 36515931
After inserting recrods in temp table i want to pull records on subsequent requests from this table(don't know if thats possible). The reason i am doing this is becasue the sp below generates random records and after generating these records I need to save them some where to access them during the user's session quiz

ALTER PROCEDURE [dbo].[sp_GetQuestionsByChapterID]
      -- Add the parameters for the stored procedure here
      @QuizID varchar(5000)
      
AS
BEGIN
      

    -- Insert statements for procedure here

select top 24 QuestionID,Question, Choices,CorrectAnswer,RelatedInfo,QuestionType, Section, row_number() over(order by QuestionNo) AS QuestionNo  from (
Select Q.QuestionID,Q.Question,Q.Choices,Q.CorrectAnswer,
Q.RelatedInfo,Q.QuestionType,Q.Section, newid() QuestionNo
FROM dbo.Questions Q
where  (CHARINDEX( ',' + convert(varchar,Q.Chapter) + ',', ',' + @QuizID + ',' ) > 0)
) x
END
0
 
LVL 9

Accepted Solution

by:
teebon earned 500 total points
ID: 36895472
Why don't you pull out the random questions and store in a session variable instead?
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Linked Server Issue with SQL2012 3 26
Help Required 3 97
C# Gridview 1 33
average of calculation (TSQL) 4 9
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

822 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question