Solved

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

Posted on 2011-09-09
6
350 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 62

Expert Comment

by:Fernando Soto
Comment Utility

Can you post the Stored Procedure.
0
 

Author Comment

by:mmalik15
Comment Utility
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
Comment Utility
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 62

Expert Comment

by:Fernando Soto
Comment Utility

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
Comment Utility
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
Comment Utility
Why don't you pull out the random questions and store in a session variable instead?
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

763 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now