i have one problem when in inserting data into the database .when user start quiz then after press next button ,at that time whatever user selecting is store in one database but actually is not stored i used detaillist view to display quiz question.
// Save off previous answers
System.Data.DataRowView dr = (System.Data.DataRowView)DetailsView1.DataItem;
// Create Answer object to save values
Answer a = new Answer();
a.QuestionID = dr["QuestionID"].ToString();
a.CorrectAnswer = dr["CorrectAnswer"].ToString();
ArrayList al = (ArrayList)Session["AnswerList"];
al.Add(a);
Session.Add("AnswerList", al);
if (DetailsView1.PageIndex == DetailsView1.PageCount - 1)
{
// Go to evaluate answers
Response.Redirect("evaluate.aspx");
}
else
{
DetailsView1.PageIndex++;
Button1.Text = "Finished";
}
error of Answer object is solved but
now i get error like:
Object reference not set to an instance of an object.
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.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
Line 104: Line 105: ArrayList al = (ArrayList)Session["AnswerList"]; Line 106: al.Add(a); Line 107: Line 108: Session.Add("AnswerList", al);
this is a standard compiler error: the compiler has no clue about your type
Answer ... if Answer is defined in a different assembly or namespace, you need to point the c# compiler in the correct direction ...
sometimes this is as simple as adding a namespace with a
using or fulling qualifying the type name:
using RavisNamespace;
or
RavisNamespace.Answer = new RavisNamespace.Answer();
at other times, you might actually have to add a Reference to the assembly that contains your type
Answer.
Please look closely at your code, is the namespace for Answer
different from the namespace for the code where you are using the type Answer to creat your object
a?
g.
B-) Please help me by completing my school survey about computer programmers on my website. Thank you!!! Gerry Lowry +1 705-429-7550 wasaga beach, ontario, canada
@
ravibagadiya TIMTOWTDI =. there is more than one way to do it
there's probably a shorter way, but this works:
put your cursor in Answer and press F12 or right click
Answer and click Go To Definition ...
if that does not help you see the namespace associated with Answer, try
Click on Answer, open the Object Browser from the view menu and search for
Answer ...
if you find Answer in the Object Browser, you may see something like Member of
xyx;
if you then drill up, by clicking on xyz, you will eventually find the namespace associated with
Answer.
Note: if all your efforts fail to locate Answer, then you will likely need to reference some external assembly where
Answer is defined.
Another possibilty: you have not yet defined Answer or you've spelled
Answer incorrectly where you've defined it.
To add references, depending on your project type, you can right click in
Solution Explorer your Reference folder and click
Add Reference... and/or you might have to right click inside your code behind file (i am not sure because i do not use code behind anymore).
g.
B-) Please help me by completing my school survey about computer programmers on my website. Thank you!!! Gerry Lowry +1 705-429-7550 wasaga beach, ontario, canada
ravibagadiya
Member
67 Points
66 Posts
quiz application
Mar 24, 2012 03:03 PM|LINK
i have one problem when in inserting data into the database .when user start quiz then after press next button ,at that time whatever user selecting is store in one database but actually is not stored i used detaillist view to display quiz question.
quiz.aspx.cs code is:
protected void Button1_Click1(object sender, EventArgs e)
{
// Save off previous answers
System.Data.DataRowView dr = (System.Data.DataRowView)DetailsView1.DataItem;
// Create Answer object to save values
Answer a = new Answer();
a.QuestionID = dr["QuestionID"].ToString();
a.CorrectAnswer = dr["CorrectAnswer"].ToString();
if (RadioButton1.Checked == true)
{
crropt = "option1";
}
else if (RadioButton2.Checked == true)
{
crropt = "option2";
}
else if (RadioButton3.Checked == true)
{
crropt = "option3";
}
else if (RadioButton4.Checked == true)
{
crropt = "option4";
}
a.UserAnswer = crropt;
ArrayList al = (ArrayList)Session["AnswerList"];
al.Add(a);
Session.Add("AnswerList", al);
if (DetailsView1.PageIndex == DetailsView1.PageCount - 1)
{
// Go to evaluate answers
Response.Redirect("evaluate.aspx");
}
else
{
DetailsView1.PageIndex++;
Button1.Text = "Finished";
}
error of Answer object is solved but
now i get error like:
Object reference not set to an instance of an object.
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.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
:
gerrylowry
All-Star
20577 Points
5721 Posts
Re: quiz application
Mar 24, 2012 03:31 PM|LINK
@ ravibagadiya
this is a standard compiler error: the compiler has no clue about your type Answer ... if Answer is defined in a different assembly or namespace, you need to point the c# compiler in the correct direction ...
sometimes this is as simple as adding a namespace with a using or fulling qualifying the type name:
using RavisNamespace;
or
RavisNamespace.Answer = new RavisNamespace.Answer();
at other times, you might actually have to add a Reference to the assembly that contains your type Answer.
Please look closely at your code, is the namespace for Answer different from the namespace for the code where you are using the type Answer to creat your object a?
g.
ravibagadiya
Member
67 Points
66 Posts
Re: quiz application
Mar 24, 2012 03:44 PM|LINK
how can i identify that Answer is defined in different assembly or namespace and how can i add Reference to the assembly that contains type Answer
gerrylowry
All-Star
20577 Points
5721 Posts
Re: quiz application
Mar 24, 2012 04:25 PM|LINK
@ ravibagadiya TIMTOWTDI =. there is more than one way to do it
there's probably a shorter way, but this works:
put your cursor in Answer and press F12 or right click Answer and click Go To Definition ...
if that does not help you see the namespace associated with Answer, try
Click on Answer, open the Object Browser from the view menu and search for Answer ...
if you find Answer in the Object Browser, you may see something like Member of xyx;
if you then drill up, by clicking on xyz, you will eventually find the namespace associated with Answer.
Note: if all your efforts fail to locate Answer, then you will likely need to reference some external assembly where Answer is defined.
Another possibilty: you have not yet defined Answer or you've spelled Answer incorrectly where you've defined it.
To add references, depending on your project type, you can right click in Solution Explorer your Reference folder and click Add Reference... and/or you might have to right click inside your code behind file (i am not sure because i do not use code behind anymore).
g.
Primillo
Star
8841 Points
1701 Posts
Re: quiz application
Mar 24, 2012 07:08 PM|LINK
Hi ravibagadiya
Here is a quiz application you can use as reference:
http://www.asp.net/web-forms/videos/building-20-applications/lesson-14-building-a-quiz-engine-4
May help
Primillo
http://www.facebook.com/programandopuntonet