Conversion from type 'DBNull' to type 'Boolean' is not valid. RRS feed

  • Question

  • Have been hitting my head on this one for a while ... 



     Protected Sub CheckBox_Click(ByVal sender As Object, e As DataGridCommandEventArgs)

                Dim SQLUpdate As String  'Saves the sql command to update when clicked

                Dim MyItem As DataGridItem
                For Each MyItem In OrderDataGrid.Items

                    'Dim ocheck As String = MyItem.Cells(0).Text

                    Dim myCkbox As CheckBox = CType(MyItem.Cells(11).Controls(1), CheckBox) 'Grabs Data in 10th row in OrderDataView
                    Dim orderId As Integer = Integer.Parse(e.Item.Cells(1).Text) 'Grabs Data in the 1st row in OrderDataView

                    Dim ckbox_present As Boolean
                    If Not myCkbox Is Nothing Then
                        If myCkbox.Checked = True Then
                            ckbox_present = True
                            ' Integer.TryParse(myCkbox.Checked, ckbox_present)
                            SQLUpdate = "UPDATE `order` SET `order`.`ordercheck` = " & ckbox_present & _
                                        "WHERE `order`.`orderid`= " & orderId
                            Response.Write("Database Updated -" & SQLUpdate) 'SB - trying to see if this gets exeucted'
                        End If
                    End If


                Response.Write("Database Updated -" & SQLUpdate) 'SB - trying to see if this gets exeucted'
            Catch ex As Exception
                ' Display a simple message box.Checked!
                Console.WriteLine("Oh OOOOH An Error Occured, Did you hit the Check Box ?", ex.Message)
            End Try
        End Sub

    AND in the html area i have ...  

    <asp:TemplateColumn HeaderText="Processed">
                                         <asp:HyperLink runat="server" NavigateUrl="" Text=""></asp:HyperLink>
                                         <asp:CheckBox ID="CheckBoxOrder" runat="server" 
                                            BorderStyle="None" oncheckedchanged="CheckBox_Click" 
                                             Checked='<%# DataBinder.Eval(Container.DataItem, "ordercheck") %>' 
                                             AutoPostBack="True" />
    Friday, August 9, 2013 4:07 PM


All replies

  • The error keeps on falling on this line ... but maybe triggered by another ... 

       <asp:CheckBox ID="CheckBoxOrder" runat="server" 

    Friday, August 9, 2013 4:09 PM
  • Ok, I fixed it by editing the sql database and

    setting everything to false until a user hit a check box to activate it to true

    Friday, August 9, 2013 4:17 PM
  • Hi sashhhhh,

    Thank you for sharing your solutions & experience here. It will be very beneficial for other community members who have similar questions.

    Best Regards,

    Monday, August 12, 2013 9:43 AM