can any one please clarify my error?

Posted by Tejamanimala under ASP.NET on 5/10/2013 | Points: 10 | Views : 990 | Status : [Member] | Replies : 8
please can any one clarify my eror i am getting this error when i wrote this command
select UserID,QuestionID,Question,SelectedOption,CorrectOption from StudentExamFullResult where UserID=@UserID

ERROR IS:---
Must declare the scalar variable "@UserID".

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.SqlClient.SqlException: Must declare the scalar variable "@UserID".

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

manimala


Responses

Posted by: Learningtorise on: 5/10/2013 [Member] Starter | Points: 25

Up
0
Down
Please share code....
By Error it is confirming that your Query is passed in SQL as :

select UserID,QuestionID,Question,SelectedOption,CorrectOption from StudentExamFullResult where UserID=@UserID

which is wrong.. Instead @UserID Should have been replaced by a value.



http://hashtagakash.wordpress.com/

Tejamanimala, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Valley on: 5/10/2013 [Member] Starter | Points: 25

Up
0
Down
Hi Teja,

Please see the below example and do it accordingly.

CREATE PROC [dbo].[GetStudentPersonalData]
(
@AdmissionNoTmp numeric(10,0)
)
as
BEGIN
select AdmissionNo,
FirstName,
MiddleName,
LastName,
DateOfBirth,
Gender,
City,
State,
ZipCode,
EmailId,
ContactNo,



from StudentPersonalData
where AdmissionNo = @AdmissionNoTmp
END

Tejamanimala, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sushant on: 5/11/2013 [Member] Starter | Points: 25

Up
0
Down
Dear mr

if u r writing stored procedure the write as following

create procedure xyz
@UserID int
as
begin
select UserID,QuestionID,Question,SelectedOption,CorrectOption from StudentExamFullResult where UserID=@UserID
end


if u are using as querey then use like this
int userid=10//note use according to ur requirment
string query="select UserID,QuestionID,Question,SelectedOption,CorrectOption from StudentExamFullResult where UserID="+ userid;



Sushat

Tejamanimala, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sriramnandha on: 5/11/2013 [Member] Starter | Points: 25

Up
0
Down

U have to pass the parameter in your storedprocedure and code.

create procedure sp_procedure product
@userid int
as
begin try
select UserID,QuestionID,Question,SelectedOption,CorrectOption from StudentExamFullResult where UserID=@userid
end try

begin catch

print 'error statement'
end catch
end


...................

sqlcommand cmd=new sqlcommand('product',con)
cmd.commandtype =commandtype.storedprocedure;
cmd.parameters.addwithvalue('@userid',userid)
cmd.execurereader();

----------------------------------


hope this will help......................

sriram

Tejamanimala, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Tejamanimala on: 5/13/2013 [Member] Starter | Points: 25

Up
0
Down
hi sushanth,
yes,am using as query,but am getting error when i used r query,actually i dont want to write query in codin part,directly i want to write the query into gridview select query property
i wrote as u said,but am getting error,and i dont want to use stored procedures.
and when i click on the user id select option am getting same id to all userid's

manimala

Tejamanimala, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sushant on: 5/13/2013 [Member] Starter | Points: 25

Up
0
Down
Dear Tejamanimala
i did not got ur prob exactly plz post ur code
i think ur are passing same id as i given u for reference
int userid=10//note use according to ur requirment
string query="select UserID,QuestionID,Question,SelectedOption,CorrectOption from StudentExamFullResult where UserID="+ userid;
this will give for all user id 10
use above code according to ur requirment
see if ur showing all use questions for all user then dont use condition "where condition" and if u are using then according to query it will show all question related to that
user id (above user id=10)
thanks


See


Sushat

Tejamanimala, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Tejamanimala on: 5/13/2013 [Member] Starter | Points: 25

Up
0
Down
hi sushanth
my code is
ALTER PROCEDURE dbo.Student
@UserID int
AS
Begin
Select UserID,QuestionID,Question,SelectedOption,CorrectOption from StudentEXamFullResult where UserID=@USerID
end

that's it,and when i click on the userid,ia want to display that userid details only

manimala

Tejamanimala, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sushant on: 5/13/2013 [Member] Starter | Points: 25

Up
0
Down
Dear manimala
no prob in ur stored procedure
plz check ur code and post it so that i can help u

Sushat

Tejamanimala, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response