none
Error Object Reference Not Set To an Instance Of an Object asp.net using vb.net RRS feed

  • Question

  • I am getting this error:Object Reference Not Set To an Instance Of an Object ? I do not know where exactly the error, Visual Basic do not show the error lineْ!!! Please help me. my code is:

        Protected Sub Button2_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button2.Click
            Dim bday As String = DropDownList11.SelectedItem.ToString & "/" & DropDownList10.SelectedItem.ToString & "/" & DropDownList12.SelectedItem.ToString
            Try
                Dim conn1 As New SqlConnection(ConfigurationManager.ConnectionStrings.Item(1).ToString)
                Dim cmd As New SqlCommand("insert into students values(@std_nn, @std_fn, @stdsecn, @std_midn, @std_ln, @std_gndr, @std_bday, @std_cbirth, @std_ident, @stdmstatus, @std_mail, @std_phone, @std_ppic, @std_rstatus, @std_spec, @std_twjavg, @std_twjtype)", conn1)

                Dim affectedrow As Integer
                cmd.Parameters.Clear()
                cmd.Parameters.AddWithValue("@std_nn", Session("studentno").ToString)
                cmd.Parameters.AddWithValue("@std_fn", TextBox2.Text)
                cmd.Parameters.AddWithValue("@stdsecn", TextBox3.Text)
                cmd.Parameters.AddWithValue("@std_midn", TextBox4.Text)
                cmd.Parameters.AddWithValue("@std_ln", TextBox5.Text)
                cmd.Parameters.AddWithValue("@std_gndr", DropDownList1.SelectedItem.ToString)
                cmd.Parameters.AddWithValue("@std_bday", bday)
                cmd.Parameters.AddWithValue("@std_cbirth", TextBox6.Text)
                cmd.Parameters.AddWithValue("@std_ident", TextBox7.Text)
                cmd.Parameters.AddWithValue("@stdmstatus", DropDownList2.SelectedItem.ToString)
                cmd.Parameters.AddWithValue("@std_mail", TextBox8.Text)
                cmd.Parameters.AddWithValue("@std_phone", TextBox9.Text)
                cmd.Parameters.AddWithValue("@std_ppic", Image1.ImageUrl.ToString)
                cmd.Parameters.AddWithValue("@std_rstatus", "waiting")
                cmd.Parameters.AddWithValue("@std_spec", DBNull.Value)
                cmd.Parameters.AddWithValue("@std_twjavg", TextBox10.Text)
                cmd.Parameters.AddWithValue("@std_twjtype", DropDownList3.SelectedItem.ToString)
                If conn1.State = ConnectionState.Closed Then
                    conn1.Open()

                    affectedrow = cmd.ExecuteNonQuery()
                End If
                conn1.Close()
                If affectedrow > 0 Then
                    add_subjects()
                    add_attachments()
                    Label1.Text = "Done"
                    Response.Redirect("Stdinfo.aspx")
                End If
            Catch ex As Exception
                Label1.Text = "error " + ex.Message()
            End Try
        End Sub
    How to fix "object reference not set to an instance of an object"
    Wednesday, July 12, 2017 6:21 PM

Answers