debug error Object reference not set to an instance of an object.


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!
 
Ad

Advertisements

C

Chris, Master of All Things Insignificant

Which object is it not happy about? You posted a lot of code but what we
need is what line in btnSubject_Click is bad. What that error is telling
you is that the variable does not point to an object. Most likely some
function is returning "nothing" and then you try to use the variable that
references "nothing".

example:

Dim i as String
i = SomeFunction
i.lenth() <---- Puke cuase i = nothing

Function SomeFunction() as string
Return Nothing
End Function

Chris

ST said:
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!
 
G

Guest

ooops sorry!! I meant to mark where it was before I sent it, and
forgot...anyway, it's marked below:

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 '>>**THIS IS WHERE
IT ERRORS OUT! dr=nothing when i debug??****
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!!

Chris said:
Which object is it not happy about? You posted a lot of code but what we
need is what line in btnSubject_Click is bad. What that error is telling
you is that the variable does not point to an object. Most likely some
function is returning "nothing" and then you try to use the variable that
references "nothing".

example:

Dim i as String
i = SomeFunction
i.lenth() <---- Puke cuase i = nothing

Function SomeFunction() as string
Return Nothing
End Function

Chris

ST said:
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!
 
S

Shuvro Mazumder [MSFT]

For Each dr In ds.Tables("SUBJECT").Rows '>>**THIS IS WHERE
IT ERRORS OUT! dr=nothing when i debug??****
lblSearch.Visible = False
exist = True
Exit For
Next

Since you're not using the variable dr inside the loop, the garbage
collector might kick in and that might be a reason you're seeing a null
value inside the loop. Add a dummy reference to the variable dr before the
"next" and see if it still shows up as null when you enter the for loop

- Shuvro

--
This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm.



ST said:
ooops sorry!! I meant to mark where it was before I sent it, and
forgot...anyway, it's marked below:

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 '>>**THIS IS WHERE
IT ERRORS OUT! dr=nothing when i debug??****
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!!

Chris said:
Which object is it not happy about? You posted a lot of code but what we
need is what line in btnSubject_Click is bad. What that error is telling
you is that the variable does not point to an object. Most likely some
function is returning "nothing" and then you try to use the variable that
references "nothing".

example:

Dim i as String
i = SomeFunction
i.lenth() <---- Puke cuase i = nothing

Function SomeFunction() as string
Return Nothing
End Function

Chris

ST said:
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.RaisePo
stBackEvent(String
 
C

Chris, Master of All Things Insignificant

Well there is an easy solution to your problem. Why it is happening will be
hard for me to tell you right now. Couple of things I notice...

1. You have an Exit For in your For loop. This mean it will just look at
the first item and then leave. Why do a for each loop? You just want to
know if rows exist, do a Rows.Count.
Dim DT as DataTable
DT = ds.Tables("SUBJECT")
if (not DT is nothing) andalso DT.Rows.Count > 0 then
Exist = True
else
Exist = False
end if
If exist = False Then
lblSearch.Text = "Subject number does not exist in the
database"
lblSearch.Visible = True
End If

2. To handle the error how you have it coded, just do this:
For Each dr In ds.Tables("SUBJECT").Rows
if dr is nothing then

else
lblSearch.Visible = False
exist = True
Exit For
end if
Next
If exist = False Then
lblSearch.Text = "Subject number does not exist in the
database"
lblSearch.Visible = True
End If

I got back to my number 1 point though, you shouldn't be using a For Each in
this case. What are you trying to accomplish in this loop?

Chris

ST said:
ooops sorry!! I meant to mark where it was before I sent it, and
forgot...anyway, it's marked below:

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 '>>**THIS IS
WHERE
IT ERRORS OUT! dr=nothing when i debug??****
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!!

Chris said:
Which object is it not happy about? You posted a lot of code but what we
need is what line in btnSubject_Click is bad. What that error is telling
you is that the variable does not point to an object. Most likely some
function is returning "nothing" and then you try to use the variable that
references "nothing".

example:

Dim i as String
i = SomeFunction
i.lenth() <---- Puke cuase i = nothing

Function SomeFunction() as string
Return Nothing
End Function

Chris

ST said:
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!
 
C

Chris, Master of All Things Insignificant

I didn't even catch that dr wasn't used in the loop. It has to be that
ds.Tables("SUBJECT") is returning "nothing" and then the calls to .Rows is
throwing the exception. I'd bet money dr has nothing to do with the
problem. Look at my post though, I think there is a better way to write the
code.

Chris



Shuvro Mazumder said:
For Each dr In ds.Tables("SUBJECT").Rows '>>**THIS IS WHERE
IT ERRORS OUT! dr=nothing when i debug??****
lblSearch.Visible = False
exist = True
Exit For
Next

Since you're not using the variable dr inside the loop, the garbage
collector might kick in and that might be a reason you're seeing a null
value inside the loop. Add a dummy reference to the variable dr before the
"next" and see if it still shows up as null when you enter the for loop

- Shuvro

--
This posting is provided "AS IS" with no warranties, and confers no
rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm.



ST said:
ooops sorry!! I meant to mark where it was before I sent it, and
forgot...anyway, it's marked below:

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 '>>**THIS IS WHERE
IT ERRORS OUT! dr=nothing when i debug??****
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!!

Chris said:
Which object is it not happy about? You posted a lot of code but what we
need is what line in btnSubject_Click is bad. What that error is telling
you is that the variable does not point to an object. Most likely some
function is returning "nothing" and then you try to use the variable that
references "nothing".

example:

Dim i as String
i = SomeFunction
i.lenth() <---- Puke cuase i = nothing

Function SomeFunction() as string
Return Nothing
End Function

Chris

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.RaisePo
stBackEvent(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!
 
Ad

Advertisements

G

Guest

Hi! I'm going to take a look at your suggestions right now and get back to
you. Oh, I'm actually taking over for someone else who wrote this code. I
just recently started trying to work with this code...and I'm also a newbie
web developer (trying to learn everything on my own)! Thanks so much for the
help! I'll be back with a response shortly...

Chris said:
Well there is an easy solution to your problem. Why it is happening will be
hard for me to tell you right now. Couple of things I notice...

1. You have an Exit For in your For loop. This mean it will just look at
the first item and then leave. Why do a for each loop? You just want to
know if rows exist, do a Rows.Count.
Dim DT as DataTable
DT = ds.Tables("SUBJECT")
if (not DT is nothing) andalso DT.Rows.Count > 0 then
Exist = True
else
Exist = False
end if
If exist = False Then
lblSearch.Text = "Subject number does not exist in the
database"
lblSearch.Visible = True
End If

2. To handle the error how you have it coded, just do this:
For Each dr In ds.Tables("SUBJECT").Rows
if dr is nothing then

else
lblSearch.Visible = False
exist = True
Exit For
end if
Next
If exist = False Then
lblSearch.Text = "Subject number does not exist in the
database"
lblSearch.Visible = True
End If

I got back to my number 1 point though, you shouldn't be using a For Each in
this case. What are you trying to accomplish in this loop?

Chris

ST said:
ooops sorry!! I meant to mark where it was before I sent it, and
forgot...anyway, it's marked below:

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 '>>**THIS IS
WHERE
IT ERRORS OUT! dr=nothing when i debug??****
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!!

Chris said:
Which object is it not happy about? You posted a lot of code but what we
need is what line in btnSubject_Click is bad. What that error is telling
you is that the variable does not point to an object. Most likely some
function is returning "nothing" and then you try to use the variable that
references "nothing".

example:

Dim i as String
i = SomeFunction
i.lenth() <---- Puke cuase i = nothing

Function SomeFunction() as string
Return Nothing
End Function

Chris

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!
 
G

Guest

hmmm, well that got rid of the error i was getting before, but now it's not
searching for the subject ID i typed it...i just keeps saying "subject does
not exist" for any ID i search for.

I also noticed that the "login failed for biopsyuser" is showing up. the
way the web app works is that anyone that is logged in as a biopsyuser CANNOT
search, and anyone logged in who belongs to a superuser group CAN run this
search. So I'm thinking this might have something to do with it...

Chris said:
Well there is an easy solution to your problem. Why it is happening will be
hard for me to tell you right now. Couple of things I notice...

1. You have an Exit For in your For loop. This mean it will just look at
the first item and then leave. Why do a for each loop? You just want to
know if rows exist, do a Rows.Count.
Dim DT as DataTable
DT = ds.Tables("SUBJECT")
if (not DT is nothing) andalso DT.Rows.Count > 0 then
Exist = True
else
Exist = False
end if
If exist = False Then
lblSearch.Text = "Subject number does not exist in the
database"
lblSearch.Visible = True
End If

2. To handle the error how you have it coded, just do this:
For Each dr In ds.Tables("SUBJECT").Rows
if dr is nothing then

else
lblSearch.Visible = False
exist = True
Exit For
end if
Next
If exist = False Then
lblSearch.Text = "Subject number does not exist in the
database"
lblSearch.Visible = True
End If

I got back to my number 1 point though, you shouldn't be using a For Each in
this case. What are you trying to accomplish in this loop?

Chris

ST said:
ooops sorry!! I meant to mark where it was before I sent it, and
forgot...anyway, it's marked below:

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 '>>**THIS IS
WHERE
IT ERRORS OUT! dr=nothing when i debug??****
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!!

Chris said:
Which object is it not happy about? You posted a lot of code but what we
need is what line in btnSubject_Click is bad. What that error is telling
you is that the variable does not point to an object. Most likely some
function is returning "nothing" and then you try to use the variable that
references "nothing".

example:

Dim i as String
i = SomeFunction
i.lenth() <---- Puke cuase i = nothing

Function SomeFunction() as string
Return Nothing
End Function

Chris

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!
 
Ad

Advertisements

C

Chris, Master of All Things Insignificant

In your case it means that the dataset does not contain the "SUBJECT" table.
You will have to research where the "SUBJECT" table was suppose to get added
to the dataset. How are you logging into your database? Sounds like the
database is rejecting your user maybe?

Chris

ST said:
hmmm, well that got rid of the error i was getting before, but now it's
not
searching for the subject ID i typed it...i just keeps saying "subject
does
not exist" for any ID i search for.

I also noticed that the "login failed for biopsyuser" is showing up. the
way the web app works is that anyone that is logged in as a biopsyuser
CANNOT
search, and anyone logged in who belongs to a superuser group CAN run this
search. So I'm thinking this might have something to do with it...

Chris said:
Well there is an easy solution to your problem. Why it is happening will
be
hard for me to tell you right now. Couple of things I notice...

1. You have an Exit For in your For loop. This mean it will just look at
the first item and then leave. Why do a for each loop? You just want to
know if rows exist, do a Rows.Count.
Dim DT as DataTable
DT = ds.Tables("SUBJECT")
if (not DT is nothing) andalso DT.Rows.Count > 0 then
Exist = True
else
Exist = False
end if
If exist = False Then
lblSearch.Text = "Subject number does not exist in
the
database"
lblSearch.Visible = True
End If

2. To handle the error how you have it coded, just do this:
For Each dr In ds.Tables("SUBJECT").Rows
if dr is nothing then

else
lblSearch.Visible = False
exist = True
Exit For
end if
Next
If exist = False Then
lblSearch.Text = "Subject number does not exist in
the
database"
lblSearch.Visible = True
End If

I got back to my number 1 point though, you shouldn't be using a For Each
in
this case. What are you trying to accomplish in this loop?

Chris

ST said:
ooops sorry!! I meant to mark where it was before I sent it, and
forgot...anyway, it's marked below:

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 '>>**THIS IS
WHERE
IT ERRORS OUT! dr=nothing when i debug??****
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!!

:

Which object is it not happy about? You posted a lot of code but what
we
need is what line in btnSubject_Click is bad. What that error is
telling
you is that the variable does not point to an object. Most likely
some
function is returning "nothing" and then you try to use the variable
that
references "nothing".

example:

Dim i as String
i = SomeFunction
i.lenth() <---- Puke cuase i = nothing

Function SomeFunction() as string
Return Nothing
End Function

Chris

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!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top