G
Guest
Hello everyone, Can anyone help me with this error above when I debug my web
app project in vstudio.net?? I can't figure it out! It was working fine for
months, and now all of a sudden it's not!!
This is the error:
[NullReferenceException: Object reference not set to an instance of an
object.]
biopsy.searchsubject.btnSubject_Click(Object Sender, EventArgs e) in
C:\INetPub\WWWRoot\biopsy\searchsubject.aspx.vb:198
System.Web.UI.WebControls.Button.OnClick(EventArgs e)
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler
sourceControl, String eventArgument)
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
System.Web.UI.Page.ProcessRequestMain() +1292
And this is my code on that page:
Public Class searchsubject
Inherits System.Web.UI.Page
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
End Sub
Dim search As Boolean = False
Protected WithEvents Label2 As System.Web.UI.WebControls.Label
Protected WithEvents Label4 As System.Web.UI.WebControls.Label
Protected WithEvents Label5 As System.Web.UI.WebControls.Label
Protected WithEvents Label6 As System.Web.UI.WebControls.Label
Protected WithEvents Label7 As System.Web.UI.WebControls.Label
Protected WithEvents Label8 As System.Web.UI.WebControls.Label
Protected WithEvents Label9 As System.Web.UI.WebControls.Label
Protected WithEvents Label10 As System.Web.UI.WebControls.Label
Protected WithEvents Label11 As System.Web.UI.WebControls.Label
Protected WithEvents Label12 As System.Web.UI.WebControls.Label
Protected WithEvents CheckBox1 As System.Web.UI.WebControls.CheckBox
Protected WithEvents txtError As System.Web.UI.WebControls.Label
Protected WithEvents dgView As System.Web.UI.WebControls.DataGrid
Protected WithEvents rptSubject As System.Web.UI.WebControls.Repeater
Protected WithEvents txtSearch As System.Web.UI.WebControls.TextBox
Protected WithEvents btnUpdate As System.Web.UI.WebControls.Button
Protected WithEvents btnView As System.Web.UI.WebControls.Button
Protected WithEvents btnSearch As System.Web.UI.WebControls.Button
Protected WithEvents lblSearch As System.Web.UI.WebControls.Label
Protected WithEvents btnNewProc As System.Web.UI.WebControls.Button
Protected WithEvents btnMain As System.Web.UI.WebControls.Button
Protected WithEvents btnLogOff As System.Web.UI.WebControls.Button
Protected WithEvents btnSubject As System.Web.UI.WebControls.Button
Protected WithEvents txtSubject As System.Web.UI.WebControls.TextBox
Protected WithEvents lblSubject As System.Web.UI.WebControls.Label
Protected WithEvents rptSubName As System.Web.UI.WebControls.Repeater
Protected WithEvents button1 As System.Web.UI.WebControls.Button
Protected WithEvents button2 As System.Web.UI.WebControls.Button
Protected WithEvents button3 As System.Web.UI.WebControls.Button
Protected WithEvents btnDNA As System.Web.UI.WebControls.Button
'NOTE: The following placeholder declaration is required by the Web Form
Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub
#End Region
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
If Not IsPostBack Then
'Clear all session variables but save the user role variable
Dim user As String = Session("Role")
Session.Abandon()
Session("Role") = user
'Hide the datagrid
If Session("Role") = "User" Then
txtError.Visible = False
dgView.Visible = False
rptSubject.Visible = False
End If
Dim proc As Integer
'Loads existing information if user clicks 'Back to Subject
Menu' from any page.
'If subject_ID is missing then exit sub and don't load anything.
Try
proc = Request.QueryString("subject_ID")
Catch err As SystemException
proc = 0
Exit Try
End Try
If proc = 0 Then
Else
txtSearch.Text = proc
Dim sender2 As System.Object
Dim e2 As System.EventArgs
btnSearch_Click(sender2, e2)
End If
If Session("Role") = "User" Then
lblSubject.Visible = False
txtSubject.Visible = False
btnSubject.Visible = False
End If
'IsPostBack
Else
End If
End Sub 'Page_load
Private Sub btnSearch_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnSearch.Click
If txtSearch.Text = "" Then
Exit Sub
Else
If Session("Role") = "User" Then
Dim connstr As New SqlConnection(Application("cn"))
'SELECTS information from the SUBJECT_DIAG_PROCEDURE,
BIOPSY, PHYSICIAN and BIOPSY_PATHOLOGY tables where the subject_id matches
the number entered into the text box
Dim c As String = "Select * from SUBJECT_DIAG_PROCEDURE s
LEFT OUTER JOIN BIOPSY_PATHOLOGY bp ON s.Procedure_ID = bp.Procedure_ID,
BIOPSY b, PHYSICIAN p where s.subject_id = '" & txtSearch.Text & "' and
b.BIOPSY_ID = s.BIOPSY_ID and p.PHYSICIAN_ID = s.PHYSICIAN_ID ORDER BY
s.PROCEDURE_ID"
Dim da As New SqlDataAdapter(c, connstr)
Dim ds As New DataSet
Try
da.Fill(ds)
dgView.DataSource = ds
Catch myerr As SqlException
txtError.Text = myerr.Message
txtError.Visible = True
Finally
DataBind()
'Displays the datagrid and any returned information
dgView.Visible = True
search = True
End Try
Else
Dim connstr As New SqlConnection(Application("cn"))
'SELECTS information from the SUBJECT_DIAG_PROCEDURE,
BIOPSY, PHYSICIAN and BIOPSY_PATHOLOGY tables where the subject_id matches
the number entered into the text box
Dim c As String = "Select * from SUBJECT_DIAG_PROCEDURE s
LEFT OUTER JOIN BIOPSY_PATHOLOGY bp ON s.Procedure_ID = bp.Procedure_ID,
BIOPSY b, PHYSICIAN p where s.subject_id = '" & txtSearch.Text & "' and
b.BIOPSY_ID = s.BIOPSY_ID and p.PHYSICIAN_ID = s.PHYSICIAN_ID ORDER BY
s.PROCEDURE_ID"
Dim da As New SqlDataAdapter(c, connstr)
Dim ds As New DataSet
Try
da.Fill(ds, "SUBJECT")
rptSubject.DataSource = ds
Catch myerr As SqlException
txtError.Text = myerr.Message
txtError.Visible = True
Finally
DataBind()
'Displays the datagrid and any returned information
rptSubject.Visible = True
search = True
Dim dr As DataRow
Dim exist As Boolean = False
For Each dr In ds.Tables("SUBJECT").Rows
lblSearch.Visible = False
exist = True
Exit For
Next
If exist = False Then
lblSearch.Text = "Subject number does not exist in
the database"
lblSearch.Visible = True
End If
End Try
End If
End If
End Sub 'btnSearch_Click
Public Sub rpt_ItemCommand(ByVal Sender As Object, ByVal e As
RepeaterCommandEventArgs)
Dim test As String = e.CommandArgument
Response.Redirect(test)
End Sub
Private Sub btnMain_Click(ByVal Sender As Object, ByVal e As
System.EventArgs) Handles btnMain.Click
Response.Redirect("index.aspx")
End Sub
Private Sub btnLogOff_Click(ByVal Sender As Object, ByVal e As
System.EventArgs) Handles btnLogOff.Click
Response.Redirect("logout.aspx")
End Sub
Private Sub btnSubject_Click(ByVal Sender As Object, ByVal e As
System.EventArgs) Handles btnSubject.Click
If txtSubject.Text = "" Then
Exit Sub
Else
Dim connstr As New SqlConnection(Application("cn"))
'SELECTS information from the SUBJECT_DIAG_PROCEDURE, BIOPSY,
PHYSICIAN and BIOPSY_PATHOLOGY tables where the subject_id matches the number
entered into the text box
Dim c As String = "Select * from SUBJECT_DIAG_PROCEDURE sdp LEFT
OUTER JOIN BIOPSY_PATHOLOGY bp ON sdp.Procedure_ID = bp.Procedure_ID, BIOPSY
b, PHYSICIAN p, SUBJECT s where s.SUBJECT_LNAME = '" & txtSubject.Text & "'
and sdp.SUBJECT_ID = s.SUBJECT_ID and b.BIOPSY_ID = sdp.BIOPSY_ID and
p.PHYSICIAN_ID = sdp.PHYSICIAN_ID ORDER BY sdp.PROCEDURE_ID"
Dim da As New SqlDataAdapter(c, connstr)
Dim ds As New DataSet
Try
da.Fill(ds, "SUBJECT")
rptSubName.DataSource = ds
Catch myerr As SqlException
txtError.Text = myerr.Message
txtError.Visible = True
Finally
DataBind()
'Displays the datagrid and any returned information
rptSubName.Visible = True
search = True
Dim dr As DataRow
Dim exist As Boolean = False
For Each dr In ds.Tables("SUBJECT").Rows
lblSearch.Visible = False
exist = True
Exit For
Next
If exist = False Then
lblSearch.Text = "Subject number does not exist in the
database"
lblSearch.Visible = True
End If
End Try
End If
End Sub
End Class
Thanks!
app project in vstudio.net?? I can't figure it out! It was working fine for
months, and now all of a sudden it's not!!
This is the error:
[NullReferenceException: Object reference not set to an instance of an
object.]
biopsy.searchsubject.btnSubject_Click(Object Sender, EventArgs e) in
C:\INetPub\WWWRoot\biopsy\searchsubject.aspx.vb:198
System.Web.UI.WebControls.Button.OnClick(EventArgs e)
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler
sourceControl, String eventArgument)
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
System.Web.UI.Page.ProcessRequestMain() +1292
And this is my code on that page:
Public Class searchsubject
Inherits System.Web.UI.Page
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
End Sub
Dim search As Boolean = False
Protected WithEvents Label2 As System.Web.UI.WebControls.Label
Protected WithEvents Label4 As System.Web.UI.WebControls.Label
Protected WithEvents Label5 As System.Web.UI.WebControls.Label
Protected WithEvents Label6 As System.Web.UI.WebControls.Label
Protected WithEvents Label7 As System.Web.UI.WebControls.Label
Protected WithEvents Label8 As System.Web.UI.WebControls.Label
Protected WithEvents Label9 As System.Web.UI.WebControls.Label
Protected WithEvents Label10 As System.Web.UI.WebControls.Label
Protected WithEvents Label11 As System.Web.UI.WebControls.Label
Protected WithEvents Label12 As System.Web.UI.WebControls.Label
Protected WithEvents CheckBox1 As System.Web.UI.WebControls.CheckBox
Protected WithEvents txtError As System.Web.UI.WebControls.Label
Protected WithEvents dgView As System.Web.UI.WebControls.DataGrid
Protected WithEvents rptSubject As System.Web.UI.WebControls.Repeater
Protected WithEvents txtSearch As System.Web.UI.WebControls.TextBox
Protected WithEvents btnUpdate As System.Web.UI.WebControls.Button
Protected WithEvents btnView As System.Web.UI.WebControls.Button
Protected WithEvents btnSearch As System.Web.UI.WebControls.Button
Protected WithEvents lblSearch As System.Web.UI.WebControls.Label
Protected WithEvents btnNewProc As System.Web.UI.WebControls.Button
Protected WithEvents btnMain As System.Web.UI.WebControls.Button
Protected WithEvents btnLogOff As System.Web.UI.WebControls.Button
Protected WithEvents btnSubject As System.Web.UI.WebControls.Button
Protected WithEvents txtSubject As System.Web.UI.WebControls.TextBox
Protected WithEvents lblSubject As System.Web.UI.WebControls.Label
Protected WithEvents rptSubName As System.Web.UI.WebControls.Repeater
Protected WithEvents button1 As System.Web.UI.WebControls.Button
Protected WithEvents button2 As System.Web.UI.WebControls.Button
Protected WithEvents button3 As System.Web.UI.WebControls.Button
Protected WithEvents btnDNA As System.Web.UI.WebControls.Button
'NOTE: The following placeholder declaration is required by the Web Form
Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub
#End Region
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
If Not IsPostBack Then
'Clear all session variables but save the user role variable
Dim user As String = Session("Role")
Session.Abandon()
Session("Role") = user
'Hide the datagrid
If Session("Role") = "User" Then
txtError.Visible = False
dgView.Visible = False
rptSubject.Visible = False
End If
Dim proc As Integer
'Loads existing information if user clicks 'Back to Subject
Menu' from any page.
'If subject_ID is missing then exit sub and don't load anything.
Try
proc = Request.QueryString("subject_ID")
Catch err As SystemException
proc = 0
Exit Try
End Try
If proc = 0 Then
Else
txtSearch.Text = proc
Dim sender2 As System.Object
Dim e2 As System.EventArgs
btnSearch_Click(sender2, e2)
End If
If Session("Role") = "User" Then
lblSubject.Visible = False
txtSubject.Visible = False
btnSubject.Visible = False
End If
'IsPostBack
Else
End If
End Sub 'Page_load
Private Sub btnSearch_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnSearch.Click
If txtSearch.Text = "" Then
Exit Sub
Else
If Session("Role") = "User" Then
Dim connstr As New SqlConnection(Application("cn"))
'SELECTS information from the SUBJECT_DIAG_PROCEDURE,
BIOPSY, PHYSICIAN and BIOPSY_PATHOLOGY tables where the subject_id matches
the number entered into the text box
Dim c As String = "Select * from SUBJECT_DIAG_PROCEDURE s
LEFT OUTER JOIN BIOPSY_PATHOLOGY bp ON s.Procedure_ID = bp.Procedure_ID,
BIOPSY b, PHYSICIAN p where s.subject_id = '" & txtSearch.Text & "' and
b.BIOPSY_ID = s.BIOPSY_ID and p.PHYSICIAN_ID = s.PHYSICIAN_ID ORDER BY
s.PROCEDURE_ID"
Dim da As New SqlDataAdapter(c, connstr)
Dim ds As New DataSet
Try
da.Fill(ds)
dgView.DataSource = ds
Catch myerr As SqlException
txtError.Text = myerr.Message
txtError.Visible = True
Finally
DataBind()
'Displays the datagrid and any returned information
dgView.Visible = True
search = True
End Try
Else
Dim connstr As New SqlConnection(Application("cn"))
'SELECTS information from the SUBJECT_DIAG_PROCEDURE,
BIOPSY, PHYSICIAN and BIOPSY_PATHOLOGY tables where the subject_id matches
the number entered into the text box
Dim c As String = "Select * from SUBJECT_DIAG_PROCEDURE s
LEFT OUTER JOIN BIOPSY_PATHOLOGY bp ON s.Procedure_ID = bp.Procedure_ID,
BIOPSY b, PHYSICIAN p where s.subject_id = '" & txtSearch.Text & "' and
b.BIOPSY_ID = s.BIOPSY_ID and p.PHYSICIAN_ID = s.PHYSICIAN_ID ORDER BY
s.PROCEDURE_ID"
Dim da As New SqlDataAdapter(c, connstr)
Dim ds As New DataSet
Try
da.Fill(ds, "SUBJECT")
rptSubject.DataSource = ds
Catch myerr As SqlException
txtError.Text = myerr.Message
txtError.Visible = True
Finally
DataBind()
'Displays the datagrid and any returned information
rptSubject.Visible = True
search = True
Dim dr As DataRow
Dim exist As Boolean = False
For Each dr In ds.Tables("SUBJECT").Rows
lblSearch.Visible = False
exist = True
Exit For
Next
If exist = False Then
lblSearch.Text = "Subject number does not exist in
the database"
lblSearch.Visible = True
End If
End Try
End If
End If
End Sub 'btnSearch_Click
Public Sub rpt_ItemCommand(ByVal Sender As Object, ByVal e As
RepeaterCommandEventArgs)
Dim test As String = e.CommandArgument
Response.Redirect(test)
End Sub
Private Sub btnMain_Click(ByVal Sender As Object, ByVal e As
System.EventArgs) Handles btnMain.Click
Response.Redirect("index.aspx")
End Sub
Private Sub btnLogOff_Click(ByVal Sender As Object, ByVal e As
System.EventArgs) Handles btnLogOff.Click
Response.Redirect("logout.aspx")
End Sub
Private Sub btnSubject_Click(ByVal Sender As Object, ByVal e As
System.EventArgs) Handles btnSubject.Click
If txtSubject.Text = "" Then
Exit Sub
Else
Dim connstr As New SqlConnection(Application("cn"))
'SELECTS information from the SUBJECT_DIAG_PROCEDURE, BIOPSY,
PHYSICIAN and BIOPSY_PATHOLOGY tables where the subject_id matches the number
entered into the text box
Dim c As String = "Select * from SUBJECT_DIAG_PROCEDURE sdp LEFT
OUTER JOIN BIOPSY_PATHOLOGY bp ON sdp.Procedure_ID = bp.Procedure_ID, BIOPSY
b, PHYSICIAN p, SUBJECT s where s.SUBJECT_LNAME = '" & txtSubject.Text & "'
and sdp.SUBJECT_ID = s.SUBJECT_ID and b.BIOPSY_ID = sdp.BIOPSY_ID and
p.PHYSICIAN_ID = sdp.PHYSICIAN_ID ORDER BY sdp.PROCEDURE_ID"
Dim da As New SqlDataAdapter(c, connstr)
Dim ds As New DataSet
Try
da.Fill(ds, "SUBJECT")
rptSubName.DataSource = ds
Catch myerr As SqlException
txtError.Text = myerr.Message
txtError.Visible = True
Finally
DataBind()
'Displays the datagrid and any returned information
rptSubName.Visible = True
search = True
Dim dr As DataRow
Dim exist As Boolean = False
For Each dr In ds.Tables("SUBJECT").Rows
lblSearch.Visible = False
exist = True
Exit For
Next
If exist = False Then
lblSearch.Text = "Subject number does not exist in the
database"
lblSearch.Visible = True
End If
End Try
End If
End Sub
End Class
Thanks!