Link to home
Start Free TrialLog in
Avatar of jianxin9
jianxin9

asked on

Runtime Error--Cannot figure out what is causing it

Hello,
I keep getting a run time error when I place this piece of code in my code behind.  I cannot figure out what is causing this.  Does anyone have any suggestions?  Thanks!  My full code behind is listed below.

//Give users the option to enter school information
         
  Protected Sub rbl1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rbl1.SelectedIndexChanged
     
  If rblAns.SelectedValue = "status_guest" Then
      RequiredFieldValidator4.enabled = True
  else
      RequiredFieldValidator4.enabled = False
  End If
 
End Sub

<%@ Page Language="c#" Debug="true" %>
 
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %>
<%@ Import Namespace="System.Net.Mail" %>
<%@ Import Namespace="System.Net" %>
 
<script runat="server" language="C#">
		 
 
 
  void Page_Load()
  {
      if (Page.IsPostBack)
      {
          questionsPanel.Visible = false;
          Message.Visible = true;  
          int correct = 0;
          if (q1.SelectedIndex == 2) correct++;
          if (q2.SelectedIndex == 4) correct++;
          if (q3.SelectedIndex == 2) correct++;
          if (q4.SelectedIndex == 0) correct++;
          if (q5.SelectedIndex == 5) correct++;
          if (q6.SelectedIndex == 1) correct++;
          if (q7.SelectedIndex == 2) correct++;
 
          LoadConn(correct);
      }
      else
      {
          questionsPanel.Visible = true;
          Message.Visible = false;  
      }
  }
 
private void LoadConn(int score)
{
    int percent;
    percent = (score*100)/7;  
  
    // Create the objects 
    OleDbConnection conn;
    OleDbCommand comm;
    
    // Instance the connection open it
    conn = new OleDbConnection("Provider = Microsoft.ACE.OLEDB.12.0; Data Source ="+ Server.MapPath("assessments.accdb")+";User Id=; Jet OLEDB:Database Password=;");
    conn.Open();
    
    // Create the insert SQL 
    string sSQL = "";
		string qname = "plagiarism"; 
    sSQL = "Insert into posttest_table(fname,lname,username,coursenum,emailId,emailId2,status,school,qname,answered,score,q1,q2,q3,q4,q5,q6,q7) values('" + fname.Text + "','" + lname.Text +"','" + portal_id.Text +"','"+course_id.Text+"','"+emailId.Text+"','"+emailId2.Text+"','"+(status.SelectedIndex+1)+"','"+ school.Text +"','"+(qname)+"',"+score+","+percent+","+(q1.SelectedIndex+1)+","+(q2.SelectedIndex+1)+","+(q3.SelectedIndex+1)+","+(q4.SelectedIndex+1)+","+(q5.SelectedIndex+1)+","+(q6.SelectedIndex+1)+","+(q7.SelectedIndex+1)+");";
   
    //  Response.Write(sSQL + "<br />");
    //  Response.End();
    //  return;
    
    // Create a command object from the connection
    comm = conn.CreateCommand ();
    comm.CommandText = sSQL;
    comm.CommandType = CommandType.Text;
 
    // Try the insert 
    try
    {
        comm.ExecuteNonQuery();
    }
    catch (Exception ex)
    {
        Response.Write("Error During DB Update: " + ex.ToString());
    }
    
    
   
    conn.Close();
    // Inserting data into the database end
     
    // Create the email body text
/* String bodyInfo = fname.Text+" "+lname.Text+" has taken the exam.\n <br />"+fname.Text  +" has scored: "+percent+" out of 100 and gotten "+score+" out of 7 questions correct.\n<br /><br />"+fname.Text  +"'s options were: \n<br /> Question 1. Plagiarism is the act of: <br />The correct answer is: using someone else's work and not giving them credit (Option 3)<br /> You Answered:  Option "+(q1.SelectedIndex+1)+"\n <br /><br />Question 2.  Which of the following is copyrighted infringement? <br />The correct answer is: all of the above (Option 5) <br />You Answered: Option "+(q2.SelectedIndex+1)+"\n <br /><br />Question 3.  Accidental plagiarism is: <br />The correct answer is: always unacceptable (Option 3) <br />You Answered: Option "+(q3.SelectedIndex+1)+"\n <br /><br />Question 4. When citing my resources it is important that I: <br />The correct answer is: use a standard citation format assigned by your professor (Option 1) <br />You Answered: Option "+(q4.SelectedIndex+1)+"\n <br /><br />Question 5. RefWorks can help you: <br />The correct answer is: a, c, d (Option 6) <br />You Answered: Option "+(q5.SelectedIndex+1)+"\n<br /><br /> Question 6. Which of the following best describes plagiarism?  <br />The correct answer is: It's a serious offense and can result in severe penalties (Option 2) <br />You Answered: Option "+(q6.SelectedIndex+1)+"\n<br /><br /> Question 7. When do you have to cite your resources? <br /> The correct answer is: when what you are writing about is someone else's idea (Option 3) <br /> You Answered: Option "+(q7.SelectedIndex+1);*/
 
 String bodyInfo = fname.Text+" "+lname.Text+" is a/an "+status.Text+", and has taken the exam for the course "+course_id.Text+".\n <br />"+fname.Text+" has scored: "+percent+" out of 100 and gotten "+score+" out of 7 questions correct.\n<br /><br />"+fname.Text  +"'s options were: \n<br /> Question 1. Plagiarism is the act of: <br />The correct answer is: using someone else's work and not giving them credit (Option c)<br /> You Answered:  Option "+Convert.ToChar(q1.SelectedIndex+97)+"\n <br /><br />Question 2.  Which of the following is copyrighted infringement? <br />The correct answer is: all of the above (Option e) <br />You Answered: Option "+Convert.ToChar(q2.SelectedIndex+97)+"\n <br /><br />Question 3.  Accidental plagiarism is: <br />The correct answer is: always unacceptable (Option c) <br />You Answered: Option "+Convert.ToChar(q3.SelectedIndex+97)+"\n <br /><br />Question 4. When citing my resources it is important that I: <br />The correct answer is: use a standard citation format assigned by your professor (Option a) <br />You Answered: Option "+Convert.ToChar(q4.SelectedIndex+97)+"\n <br /><br />Question 5. RefWorks can help you: <br />The correct answer is: a, c, d (Option f) <br />You Answered: Option "+Convert.ToChar(q5.SelectedIndex+97)+"\n<br /><br /> Question 6. Which of the following best describes plagiarism?  <br />The correct answer is: It's a serious offense and can result in severe penalties (Option b) <br />You Answered: Option "+Convert.ToChar(q6.SelectedIndex+97)+"\n<br /><br /> Question 7. When do you have to cite your resources? <br /> The correct answer is: when what you are writing about is someone else's idea (Option c) <br /> You Answered: Option "+Convert.ToChar(q7.SelectedIndex+97);
 
 
    // Create SMTP client
    SmtpClient client = new SmtpClient("");
        
    // Create SMTP message
    MailMessage message = new MailMessage();
 
    // Set message properties 
    message.From = new MailAddress ("");
    message.To.Add("");
    message.CC.Add(emailId.Text);
   if (!string.IsNullOrEmpty(emailId2.Text))
    {
       message.CC.Add(emailId2.Text);
    }
    message.Body = bodyInfo;
    message.Subject = "Doing Research: Plagiarism Quiz Results";
    message.IsBodyHtml = true;
   
    try
        {
 
            // Send EMail
            client.Send(message);
        }
        catch (Exception ex)
        {
            // Do Nothing  
        }
				
 
    // Send the user to the Results page
    Response.Redirect("results.aspx?fname="+fname.Text+"&lname="+lname.Text+"&score="+percent+"&q1="+(q1.SelectedIndex)+"&q2="+(q2.SelectedIndex)+"&q3="+(q3.SelectedIndex)+"&q4="+(q4.SelectedIndex)+"&q5="+(q5.SelectedIndex)+"&q6="+(q6.SelectedIndex)+"&q7="+(q7.SelectedIndex));
 
}
 
//Give users the option to enter school information
         
  Protected Sub rbl1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rbl1.SelectedIndexChanged
     
  If rblAns.SelectedValue = "status_guest" Then
      RequiredFieldValidator4.enabled = True
  else
      RequiredFieldValidator4.enabled = False
  End If
 
End Sub
 
 
 </script>

Open in new window

Avatar of p_davis
p_davis

what is the error and what line does it occur on?
it might be this

rblAns.SelectedValue = "status_guest"

is selected value an object if so you would have to either Convert it to string or cast it.
Avatar of jianxin9

ASKER

Thanks for posting.  This is the error.  I only get it when I place that piece of code in code behind--otherwise I don't get it.  And I've checked my web.config file and  it set for <customErrors mode="Off"/>

   
 Runtime Error
Description: An application error occurred on the server. The current custom error settings for this application prevent the details of the application error from being viewed remotely (for security reasons). It could, however, be viewed by browsers running on the local server machine.
 
Details: To enable the details of this specific error message to be viewable on remote machines, please create a <customErrors> tag within a "web.config" configuration file located in the root directory of the current web application. This <customErrors> tag should then have its "mode" attribute set to "Off".
 
<!-- Web.Config Configuration File -->
 
<configuration>
    <system.web>
        <customErrors mode="Off"/>
    </system.web>
</configuration>
 
 
Notes: The current error page you are seeing can be replaced by a custom error page by modifying the "defaultRedirect" attribute of the application's <customErrors> configuration tag to point to a custom error page URL.
 
<!-- Web.Config Configuration File -->
 
<configuration>
    <system.web>
        <customErrors mode="RemoteOnly" defaultRedirect="mycustompage.htm"/>
    </system.web>
</configuration>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of JMoon5FTM
JMoon5FTM

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
that's it--thanks!