Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Mar 24, 2012 07:08 PM by Primillo
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"];
if (DetailsView1.PageIndex == DetailsView1.PageCount - 1)
// Go to evaluate answers
Button1.Text = "Finished";
error of Answer object is solved but
now i get error like:
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.
Line 104:Line 105: ArrayList al = (ArrayList)Session["AnswerList"];Line 106: al.Add(a);Line 107:Line 108: Session.Add("AnswerList", al);
Mar 24, 2012 03:31 PM|LINK
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:
RavisNamespace.Answer = new RavisNamespace.Answer();
at other times, you might actually have to add a Reference to the assembly that contains your type
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
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
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
if you find Answer in the Object Browser, you may see something like Member of
if you then drill up, by clicking on
xyz, you will eventually find the namespace associated with
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).
Mar 24, 2012 07:08 PM|LINK
Here is a quiz application you can use as reference: