Click here to Skip to main content
15,919,931 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

I am facing some problem in passing data table parameter to stored procedure.

There are two table
tblQuestion and tblAnswerChoice

1. tblQuestion is for storing questions and its columns are
a)Qid int primary key identity
b)Question ntext
c)Createiondate datetime

2. tblAnswerChoice is for storing Answer Choices for the particular question and its columns are
a)Ansid int primary key identity
b)qid int
c)AnswerChoice ntext


Now about the problem I want to update the data of the tblAnswerChoiceI am passing the datatable as parameter to the datatabse. I need the stored procedure for updating the datatbase. Is is possible using table datatype or not. If yes then how to write the stored procedure for update the tblAnswerChoice. If table stored procedure is not use in this case, how can I update the tblAnswerChoice

Thanks,
Deepak Pandey
Posted
Comments
Bala Selvanayagam 9-Oct-11 7:17am    
Just revised my stored procedure...and have a look

1 solution

You type should be

SQL
CREATE TYPE [dbo].[tblAnswerChoiceTypeUpdate] AS TABLE(
    [AnsID]         int,
    [answerchoice] [ntext] NULL
)



The stored procedure should be

SQL
CREATE procedure [dbo].[spUpdateAnswerChoice] @dtanswerchoice tblAnswerChoiceTypeUpdate READONLY as
Begin

    update tblAnswerChoice
    set AnswerChoice=@dtanswerchoice.answerchoice
    from tblAnswerChoice,@dtanswerchoice
    where tblAnswerChoice.AnsID=@dtanswerchoice.AnsID

End



Hope this helps
 
Share this answer
 
v2
Comments
aryan2010 9-Oct-11 13:12pm    
The above code is showing this error
Msg 137, Level 16, State 1, Procedure sp_update_quiz_question, Line 54
Must declare the scalar variable "@dtanswerchoice".

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