2013-08-06 146 views
-2
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click 
     Dim score As Integer 

    If RadioButtonList1.SelectedValue = "Be careful indexing attributes that have null values." Then 
     score = score + 1 
     Session("correct") = "Be careful indexing attributes that have null values." 
     Session("question") = "1.A rule of thumb for choosing indexes for a relational database includes which of the following?" 
     Session("yourans") = "Be careful indexing attributes that have null values." 
     Session("score1") = 1 
    ElseIf RadioButtonList1.SelectedValue = "Indexes are more useful on smaller tables." Then 
     score = score + 0 
     Session("correct") = "Be careful indexing attributes that have null values." 
     Session("question") = "1.A rule of thumb for choosing indexes for a relational database includes which of the following?" 
     Session("yourans") = "Indexes are more useful on smaller tables." 
     Session("score1") = 0 
    ElseIf RadioButtonList1.SelectedValue = "Indexes are more useful for columns that do not appear frequently in the WHERE clause in queries." Then 
     score = score + 0 
     Session("correct") = "Be careful indexing attributes that have null values." 
     Session("question") = "1.A rule of thumb for choosing indexes for a relational database includes which of the following?" 
     Session("yourans") = "Indexes are more useful for columns that do not appear frequently in the WHERE clause in queries." 
     Session("score1") = 0 
    ElseIf RadioButtonList1.SelectedValue = "Do not specify a unique index for the primary key of each table." Then 
     score = score + 0 
     Session("correct") = "Be careful indexing attributes that have null values." 
     Session("question") = "1.A rule of thumb for choosing indexes for a relational database includes which of the following?" 
     Session("yourans") = "Do not specify a unique index for the primary key of each table." 
     Session("score1") = 0 
    ElseIf RadioButtonList1.SelectedValue = "" Then 
     score = score + 0 
     Session("correct") = "Be careful indexing attributes that have null values." 
     Session("question") = "1.A rule of thumb for choosing indexes for a relational database includes which of the following?" 
     Session("yourans") = "No Answer" 
     Session("score1") = 0 
    End If 


    Session("per") = Math.Round(score/1 * 100) 
    If Session("per") <= 50 Then 
     Session("state") = "Poor Your Aptitude skills need to be improved!" 
    ElseIf Session("per") <= 60 Then 
     Session("state") = "Poor spend more time!" 
    ElseIf Session("per") <= 70 Then 
     Session("state") = "Not bad You need to pratice!" 
    ElseIf Session("per") <= 80 Then 
     Session("state") = "good with a little more work You could be really proud!" 
    ElseIf Session("per") <= 90 Then 
     Session("state") = "Very good you still missed one or more question pratice!" 
    ElseIf Session("per") <= 99 Then 
     Session("state") = " Excellent Which question(s) did You Miss!" 
    ElseIf Session("per") <= 100 Then 
     Session("state") = "Perfect You Should be really Product!" 
    End If 
    Session("a13") = "You score is " & score _ 
    & " Out of 10," & Session("per") & "%," & Session("state") 
    Session("f") = score 
    con.Open() 
    qur = "insert into res values('" + Session("rn").ToString() + "','" + Session("na").ToString() + "','" + Session("cl").ToString() + "','" + Session("de").ToString() + "','" + Session("da").ToString() + "','" + Session("mn").ToString() + "','" + Session("em").ToString() + "','" + Session("f").ToString() + "','" + Session("per").ToString() + "','" + Session("state").ToString() + "')" 
    cmd = New SqlCommand(qur, con) 
    cmd.ExecuteNonQuery() 
    cmd.Dispose() 
    con.Close() 
    Response.Redirect("Aptituderesult.aspx") 
End Sub 

結果頁面的實例對象引用錯誤如何避免不設置到對象

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load 
    Label1.Text = Session("us11").ToString() 
    Label2.Text = Session("question").ToString() 
    Label3.Text = Session("correct").ToString() 
    Label4.Text = Session("yourans").ToString() 
    Label5.Text = Session("score1").ToString() 
    Label6.Text = Session("a13").ToString() 
End Sub 

任何一個可以幫助我

+0

可以共享錯誤日誌?你想達到什麼目的? – SeeSharp

+0

am在線開發aptitude test projects.resulting頁面顯示對象引用錯誤未設置爲對象實例 – user2655643

+0

您仍然不清楚在哪個地方以及在哪個事件發生後出現此錯誤? – SeeSharp

回答

0

當這種類型的錯誤發生,那麼它很明顯,你有沒有初始化控制的價值等,並試圖使用相同的。 在這種情況下,由於會話可能爲空,因此值不能從會話中重試,因此沒有相同的值。 更好的方法是檢查,例如:

if(Session["us11"]!=null) 
{ 
..//the assign the value 
} 
+0

沒有什麼可顯示的結果頁面 – user2655643

+0

am打開一個新的並開發它工作的結果頁面page.thank u – user2655643