Solved

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

Posted on 2011-09-09
6
364 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

 
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

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

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

Naughty Me. While I was changing the database name from DB1 to DB_PROD1 (yep it's not real database name ^v^), I changed the database name and notified my application fellows that I did it. They turn on the application, and everything is working. A …
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

730 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