Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
1176
wingrid error when loading data
posted

 i have this procedure that fill my wingrid but i have an intermitent problem, if i ran my process 30 times only 2 or 3 times will throw the following error, any idea on what is wrong with my code or is a wingrid problem?

Error

not alway same error, but intermitent, all of them had results the store procedure

1)   ************** Exception Text **************
System.ArgumentException: An item with the same key has already been added.
   at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)

2) ************** Exception Text **************
System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index

Code

 Private Sub LoadResults(ByVal StrFromDate As String, ByVal StrPercentage As String)
        Dim DS As DataSet = New DataSet

        Try
            QueryHst = False
            DS.Tables.Clear()
            Application.DoEvents()

            DS.Tables.Add(Conn.GetData("exec sp_DataGetPriceError " & _
                                    "@FromDate = '" + StrFromDate + "', " & _
                                    "@Percentage = " + IIf(StrPercentage = 100, "1.0", "0." + Format(CInt(StrPercentage), "00").ToString)))

            'Show the grid
            dgv1.ResetLayouts()
            dgv1.SetDataBinding(DS, "table1")

            ShowAnimation(False)

        Catch Ex As Exception

            Conn.LogError(gUser.pUserID.ToString, My.Computer.Name.ToString, "Frm Price Error", "Load Results", "value change", "1", Ex.Message.ToString)
        End Try

    End Sub

store procedure always return a value.

Image

Parents
  • 469350
    Suggested Answer
    Offline posted

    The big red X you are seeing here means that an exception occurred in the OnPaint of a control. This is not specific to the grid, it happens with any control.

    So the question is... why is an exception occurring when the grid is painting. It might help to see the details of the exception (by pushing the Details button on the error dialog).

    But my guess is that it's the DoEvents call you have in your code. Using DoEvents is generally a bad idea and should be avoided unless absolutely neccessary. Even Microsoft's documentation advises against using it because it can change the order of events and cause unexpected results.

    If I am wrong, and it's not the DoEvents, then my next guess would be that your application is using multiple threads.

Reply Children