checking my Checkbox on Runtime Error

andycharger

Centurion
Joined
Apr 2, 2003
Messages
152
I have a checkbox on my screen that I need to Check or uncheck depending on what the database says.

So during my page load, im querying the database and pulling back the record i need.

I then check the data using an if statement that works. However, when it tries to set my Checkbox to the right condition, the page falls over. Can someone help me and tell me what im doing wrong?

Here is my code:

At the top of the Code page I have this:
Code:
Protected WithEvents chkOMB As System.Web.UI.WebControls.CheckBox

My code does the following.
Code:
 Dim strUser As String
        Dim Choices As String
        Dim oConn As SqlConnection
        Dim oComm As SqlCommand
        Dim strUserPerson As String
        Dim oReader As SqlDataReader
        Dim sSQL As String
        Dim sConn As String

        sSQL = "SELECT * FROM complaints where complaint_id = " & Request.QueryString("complaint_id") & ""
        sConn = ConfigurationSettings.AppSettings("ConnectionString")

        oConn = New SqlConnection(sConn)
        oConn.Open()

        oComm = New SqlCommand(sSQL, oConn)
        oReader = oComm.ExecuteReader()
        While oReader.Read
            If IsDBNull(oReader("ombudsman_yesno")) Then
                chkOMB.Checked = False
            Else
                If oReader("ombudsman_yesno") = "True" Then
                    chkOMB.Checked = True
                Else
                    chkOMB.Checked = False

                End If
            End If



        End While

        dgnews.DataSource = oReader



        dgnews.DataBind()


        oConn.Close()

The aspx code on the page is as follows:
Code:
<td class="normaltext" align="left" colspan="2"><asp:CheckBox id="chkOMB" runat="server" Enabled="true"></asp:CheckBox></td>

can anyone help me?
 
OK Maybe I should elaborate......

The error I am getting is thus:
Code:
Server Error in '/inet1' Application.
--------------------------------------------------------------------------------

Object reference not set to an instance of an object. 
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error: 


Line 56:         While oReader.Read
Line 57:             If IsDBNull(oReader("ombudsman_yesno")) Then
Line 58:                 chkOMB.Checked = False
Line 59:             Else
Line 60:                 If oReader("ombudsman_yesno") = "True" Then
 

Source File: c:\inetpub\wwwroot\inet1\complaints\editcomplaint.aspx.vb    Line: 58 

Stack Trace: 


[NullReferenceException: Object reference not set to an instance of an object.]
   inet1.editcomplaint.Page_Load(Object sender, EventArgs e) in c:\inetpub\wwwroot\inet1\complaints\editcomplaint.aspx.vb:58
   System.Web.UI.Control.OnLoad(EventArgs e)
   System.Web.UI.Control.LoadRecursive()
   System.Web.UI.Page.ProcessRequestMain()

Basically, I am running the following IF statement on Page Load after I have set my datasource up. I know it is able to read the values when I step into the code. It just cant set the chkOMB to an item on the page even though it exists.

Here is my IF statement:

Code:
 While oReader.Read
            If IsDBNull(oReader("ombudsman_yesno")) Then
                chkOMB.Checked = False
            Else
                If oReader("ombudsman_yesno") = "True" Then
                    chkOMB.Checked = True
                Else
                    chkOMB.Checked = False

                End If
            End If



        End While

anyone got any ideas?
 
Back
Top