Errors Creating a datagridview with Checkboxes

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Amanda Hartley
    New Member
    • Jan 2012
    • 3

    Errors Creating a datagridview with Checkboxes

    I am Getting an error of
    Title: DataGridView Default Error Dialog
    Content: The following Exception occurred in the DataGridView:
    System.Exceptio n: Sent to Pinnacle 01/23/2012 is not a valid Value for Double. ---> System.FormatEx ception: Input String was not in a correct Format.
    at System.number.s tringtoNumber(S tring str, NumberStyles Options, NumberBuffer& number, NumberFormatInf o info, Boolean parseDecimal)
    There is more to this error but pretty much the same content as above over and over again.

    Code:
        Private Sub LoadExceptions(ByVal ct As Integer, ByVal sqlQry As String)
            grdExceptions.BringToFront()
            grdExceptions.Rows.Clear()
            grdExceptions.Columns.Clear()
    
            Dim strSql As String
    
            Dim ownerFld As String = cbOwner.Text '.Substring(1, 1)
            Dim contractFld As String = cbContract.Text '.Substring(1, 1)
            Dim ResortID As String = lvResortsA.SelectedItems(0).SubItems(0).Text.ToString.Split(":")(0)
    
            Dim recCt As Integer = grdResult.RowCount
            Dim sqldr As SqlDataReader
    
            Dim myFields As String = "Updated:ResortID:OwnerID:ContractID:Collector:Description:User1:User2:User3:User4:User5:Errors "
           
     Dim splitFlds() As String = myFields.Split(":")
            Dim fldct As Integer = myFields.Split(":").Count
            For F As Integer = 0 To fldct - 1
                Dim colName As String = splitFlds(F)
                If F = 0 Then
                    Dim ChkBox As New DataGridViewCheckBoxColumn
                    grdExceptions.Columns.Insert(0, ChkBox)
                    grdExceptions.Columns(F).Name = colName
                    grdExceptions.Columns(F).ReadOnly = False
                Else
                    grdExceptions.Columns.Add(colName, colName)
                    grdExceptions.Columns(F).ReadOnly = False
                End If
            Next
    
            Dim hdrRec As Integer = 0
            If rbYes.Checked Then hdrRec = 1
            ProgressBar1.Maximum = grdResult.RowCount - (hdrRec + 1)
            ProgressBar1.Step = 1
            If hdrRec = 1 Then recCt = recCt - 1
            For D As Integer = (0 + hdrRec) To recCt - 1
    
                ProgressBar1.PerformStep()
                Dim OwnerId As String = grdResult.Rows(D).Cells(ownerFld).Value.ToString.Trim
                Dim ContractId As String = grdResult.Rows(D).Cells(contractFld).Value.ToString.Trim
                'myWhere = " where "
    
                Try
                    Dim Con As New SqlConnection(g_DbConnStrings.CudbSqlConnStr)
                    Con.Open()
                    Dim rdr As SqlDataReader = Nothing
                    strSql = sqlQry
                   
                    If strSql.ToString.ToUpper.Contains("WHERE") Then
                        strSql &= " AND ownerID = '" & OwnerId & "' and contractID = '" & ContractId & "' and ResortID = '" & ResortID & "'"
                    Else
                        strSql &= " Where ownerID = '" & OwnerId & "' and contractID = '" & ContractId & "' and ResortID = '" & ResortID & "'"
                    End If
                    Dim Rw As vs.Controls.TableView.Row
                    Dim cmd As New SqlCommand(strSql, Con)
    
                    rdr = cmd.ExecuteReader()
                    While rdr.Read
    
                        ProgressBar1.PerformStep()
                        gLblStatus.Text = "Searching for Exceptions"
                        gLblStatus.gLblPulse = True
    
                        Dim errText As String = ""
                        Dim ckErr As Boolean = False
                        Dim collector As String = IIf(IsDBNull(rdr.Item(3).ToString.Trim), "", rdr.Item(3).ToString.Trim)
                        If ckUD6a.Checked = True Then
                            If collector.Trim <> cbUD6a.Text.Split(":")(0).Trim Then
                                ckErr = True
                                errText = " Invalid Collector;"
                            End If
                        End If
                        Dim note As String = IIf(IsDBNull(rdr.Item(4).ToString.Trim), "", rdr.Item(4).ToString.Trim) 'Sample Output = 'Sent to Pinnacle 01/23/2012'
                        If ckAddDesc.Checked = True Then
                            If txtDescription.Text.Trim <> note Then
                                ckErr = True
                                errText &= " Invalid Description;"
                            End If
                        End If
    
                        Dim UD1 As String = IIf(IsDBNull(rdr.Item(5).ToString.Trim), "", rdr.Item(5).ToString.Trim) 'Sample Output = Collections'
                        If ckUD1a.Checked = True Then
                            If cbUD1a.Text.Trim <> UD1 Then
                                ckErr = True
                                errText &= " Invalid User Field 1;"
                            End If
                        End If
    
                        Dim UD2 As String = IIf(IsDBNull(rdr.Item(6).ToString.Trim), "", rdr.Item(6).ToString.Trim) 'Sample Output = 'Nothing'
                        If ckUD2a.Checked = True Then
                            If cbUD2a.Text.Trim <> UD2 Then
                                ckErr = True
                                errText &= " Invalid User Field 2;"
                            End If
                        End If
                        Dim UD3 As String = IIf(IsDBNull(rdr.Item(7).ToString.Trim), "", rdr.Item(7).ToString.Trim) 'Sample Output = 'Nothing'
                        If ckUD3a.Checked = True Then
                            If cbUD3a.Text.Trim <> UD3 Then
                                ckErr = True
                                errText &= " Invalid User Field 3;"
                            End If
                        End If
                        Dim UD4 As String = IIf(IsDBNull(rdr.Item(8).ToString.Trim), "", rdr.Item(8).ToString.Trim) 'Sample Output = 'Nothing'
                        If ckUD4a.Checked = True Then
                            If cbUD4a.Text.Trim <> UD4 Then
                                ckErr = True
                                errText &= " Invalid User Field 4;"
                            End If
                        End If
                        Dim UD5 As String = IIf(IsDBNull(rdr.Item(9).ToString.Trim), "", rdr.Item(9).ToString.Trim) 'Sample Output = ''
                        If ckUD5a.Checked = True Then
                            If cbUD5a.Text.Trim <> UD5 Then
                                ckErr = True
                                errText &= " Invalid User Field 5;"
                            End If
                        End If
                        If ckErr = True Then
                            grdResult.Rows.Item(D).Cells(0).Value = True
                        Else
                            grdResult.Rows.Item(D).Cells(0).Value = False
                        End If
                        grdResult.Rows(D).Cells(1).Value = ResortID
                        grdResult.Rows(D).Cells(2).Value = OwnerId
                        grdResult.Rows(D).Cells(3).Value = ContractId
                        grdResult.Rows(D).Cells(4).Value = collector
                        grdResult.Rows(D).Cells(5).Value = note  ''System.Exception: Sent to Pinnacle 01/23/2012 is not a valid Value for Double. --->
                        grdResult.Rows(D).Cells(6).Value = UD1  ''System.Exception: Collections is not a valid Value for Decimal. --->
                        grdResult.Rows(D).Cells(7).Value = UD2  ''System.Exception: is not a valid Value for Decimal. --->
                        grdResult.Rows(D).Cells(8).Value = UD3
                        grdResult.Rows(D).Cells(9).Value = UD4
                        grdResult.Rows(D).Cells(10).Value = UD5
                        grdResult.Rows(D).Cells(11).Value = errText
    
    
                    End While
                    rdr.Close()
                    Con.Close()
    
    
    
                Catch ex As System.Exception
                    MsgBox(ex.Message, MsgBoxStyle.Critical)
                    Sys.IO.MyLog.Write(Date.Today, ": " & ex.Message, EventLogEntryType.Error)
                End Try
    
            Next
            gLblStatus.Text = "Waiting on User...."
            gLblStatus.gLblPulse = False
            ProgressBar1.Value = 0
            sqlConnections.Close()
            SqlCmd = Nothing
            sqldr = Nothing
    
         
        End Sub
    I am basically updating my database with my results table and this routine goes back in and checks the database to ensure all fields were updated correctly with the appropriate data and checks any boxes where the results brought back are incorrect or do not match, or the row was skipped based on criteria specified on my original Query.

    I apologize for the immature style of coding as I am self educated in VB.Net Programming. I am sure there are more effective ways to accomplish what I have written, but for the most part my code does exactly what I need it to do.

    Thank you for any assistance you can offer!
    If you need more information I would be happy to provide anything you may need to assist me.

    -Amanda-
Working...