[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Runtime Error--Cannot figure out what is causing it

Posted on 2008-11-10
5
Medium Priority
?
363 Views
Last Modified: 2012-05-05
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

0
Comment
Question by:jianxin9
  • 2
  • 2
5 Comments
 
LVL 22

Expert Comment

by:p_davis
ID: 22921922
what is the error and what line does it occur on?
0
 
LVL 22

Expert Comment

by:p_davis
ID: 22921968
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.
0
 

Author Comment

by:jianxin9
ID: 22922126
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

0
 
LVL 5

Accepted Solution

by:
JMoon5FTM earned 2000 total points
ID: 22923670
You're posting a VB.net script into a C# script block.  You'll need to either convert it to C# or use another script block with the language set correctly.
0
 

Author Closing Comment

by:jianxin9
ID: 31515035
that's it--thanks!
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Hello there! As a developer I have modified and refactored the unit tests which was written by fellow developers in the past. On the course, I have gone through various misconceptions and technical challenges when it comes to implementation. I would…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

872 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question