BeforeColUpdate (Data type mismatch during update)

Posted by: juan.ome on 13 March 2018, 4:10 am EST

    • Post Options:
    • Link

    Posted 13 March 2018, 4:10 am EST

    I have a True DBGrid pro 8 (OLEDB) and its dataSource is an ADO 2.8, on beforeColUpdate, when I try click on a check column, I try to update a column directly on ADO and grid , but I get the msgbox with the subject error:

    Public Sub tdbgrdAplicacion_BeforeColUpdate(ByVal ColIndex As Integer, OldValue As Variant, Cancel As Integer)

    Select Case ColIndex

    Case EnumColumnaAplicacionAplicar

    tdbgrdAplicacion.Columns(EnumColumnaAplicacionDocto).Value = “aplicar”

    recAdoAplicacion.Fields(“doccruce”).Value = “aplicar”

            tdbgrdAplicacion.Columns(EnumColumnaAplicacionVlrPPago).Value = 0
            recAdoAplicacion.Fields("valorprontopago").Value = 0
    End Select
    

    End Sub

    Can anyone know how to fix this?

    Thx anyway.

    ErrorGrid8.zip

  • Posted 13 March 2018, 4:13 am EST

    I forget… it is on VB6

  • Posted 13 March 2018, 6:13 pm EST

    Hi,

    Thank you for sharing the application.

    In order to resolve this, please call TrueDBGrid’s Update method after actually updating the value in BeforeColUpdate event:

    
    Public Sub tdbgrdAplicacion_BeforeColUpdate(ByVal ColIndex As Integer, OldValue As Variant, Cancel As Integer)
        Select Case ColIndex
            Case EnumColumnaAplicacionAplicar ' Aplicar
                tdbgrdAplicacion.Columns(EnumColumnaAplicacionVlrAAplicar).Value = 0
                recAdoAplicacion.Fields("valoraaplicar").Value = 0
                tdbgrdAplicacion.Update
                 
                tdbgrdAplicacion.Columns(EnumColumnaAplicacionVlrPPago).Value = 0
                recAdoAplicacion.Fields("valorprontopago").Value = 0
                
        End Select
    lblsalir:
    End Sub
    
    

    Thanks,

    Pragati

  • Posted 9 April 2018, 3:21 am EST

    Thanks for your response, I made the change in the line code as you proposed but it does not work, I tried to use the PostEvent Event but it did’nt work either.

  • Posted 9 April 2018, 9:46 pm EST

    Hi,

    Can you please try using the latest build which can be downloaded from the link below:

    http://prerelease.componentone.com/activex/c1truedbgrid/2017-t3/TrueDBGrid8_8.0.20173.378.zip

    It works fine at my end.

    Thanks.

  • Posted 20 April 2018, 6:45 am EST

    Hi… it’s not working yet… I try using the version that you propose (378) but it’s not not working. I’m attaching the file of evidence of use of correct version. I have not idea what can I do.

  • Posted 20 April 2018, 8:00 am EST - Updated 3 October 2022, 11:13 pm EST

  • Posted 23 April 2018, 8:25 pm EST

    Hi,

    Can you please modify the application I shared and send back such that I can replicate the problem at my end and see what is going wrong in your code?

    Thanks,

    Pragati

  • Posted 24 April 2018, 3:08 am EST

    Thanks about your disposition. I’m attaching the source code with your code propounded. Note: I made the test with TDB v.7 and it is reporting the same error.ErrorTDB_v_8_0_20173_378.zip

    Thanks, Claudia

  • Posted 26 April 2018, 5:31 pm EST

    Hi,

    I could also replicate the issue using your sample at my end. I am discussing it with the developers and will let you know once we reach to a conclusion.

    Thanks,

    Pragati

  • Posted 27 April 2018, 3:57 am EST

    Finally! it’s great…I’ll be waiting your response!!!

  • Posted 29 April 2018, 3:36 pm EST

    Hi,

    As per the developers, the sample performs Column updates before the current record is placed into edit mode. As a result, the data in the grid has changed when an attempt has been made to update the recordset - i.e. the grid is left in an unstable state. This is because the changes were attempted in BeforeColUpdate. BeforeColUpdate is provided as a means to cancel the column changes, not make additional column changes.

    There are a couple optional solutions:

    1. make the updates in AfterColUpdate. In AfterColUpdate, the record is already be opened for editing.
    2. change the order of the record updates in BeforeColUpdate. If the recordset field updates are made first, the record is opened for editing prior to changing the column in the grid. This is an appropriate state to change the column values.

    e.g.:

    
    Private Sub tdbgrdAplicacion_AfterColUpdate(ByVal ColIndex As Integer)
        Select Case ColIndex
            Case EnumColumnaAplicacionAplicar ' Aplicar
                tdbgrdAplicacion.Columns(EnumColumnaAplicacionVlrAAplicar).Value = 0
                recAdoAplicacion.Fields("valoraaplicar").Value = 0
    
                tdbgrdAplicacion.Columns(EnumColumnaAplicacionVlrPPago).Value = 0
                recAdoAplicacion.Fields("valorprontopago").Value = 0
        End Select
    End Sub
    
    

    ---- or ----

    
    Public Sub tdbgrdAplicacion_BeforeColUpdate(ByVal ColIndex As Integer, OldValue As Variant, Cancel As Integer)
        Select Case ColIndex
            Case EnumColumnaAplicacionAplicar ' Aplicar
                ''''''''''tdbgrdAplicacion.Columns(EnumColumnaAplicacionVlrAAplicar).Value = 0
                recAdoAplicacion.Fields("valoraaplicar").Value = 0
                tdbgrdAplicacion.Columns(EnumColumnaAplicacionVlrAAplicar).Value = 0
    
                ''''''''''tdbgrdAplicacion.Columns(EnumColumnaAplicacionVlrPPago).Value = 0
                recAdoAplicacion.Fields("valorprontopago").Value = 0
                tdbgrdAplicacion.Columns(EnumColumnaAplicacionVlrPPago).Value = 0
        End Select
    lblsalir:
    End Sub
    
    

    Thanks,

    Pragati

  • Posted 3 May 2018, 12:37 am EST

    Thanks… The “problem” with the AfterColUpdate is that it is not possible to reverse(cancel) a operation; obviusly I sent you a little example about the error, but really there are many other operations and it is very important it can be canceled… I will test the second option.

    thanks, Claudia

  • Posted 4 May 2018, 3:39 am EST

    Hi Pragati,

    On another hand, this is a code that work fine with the version 6, but now we are trying to migrate to version 7 or 8 and, because that error, it is not been possible.

  • Posted 6 May 2018, 8:44 pm EST

    Hi Claudia,

    I understand the reason for not using the AfterColUpdate event. Have you tried the second option? Were you able to resolve the error using the same?

    ~Pragati

  • Posted 28 May 2018, 1:11 am EST

    hi Pagati,

    We was testing the second option, but it means we need to do many changes of code. This solution means that really does not exists a clear support between version 6 to versions 7 or 8 ? If we decide to change to versions 7 or 8, we need to rewrite the code and test it again? We have nearly 907 trueDbGrids in the application, not all are editables, but if we have to change 100, it has a very hi impact in the project… this information is for you can understand we preocupation about the solution you did propouse.

    thanks in advance, Claudia

  • Posted 28 May 2018, 8:29 pm EST

    Hi Claudia,

    There have been many changes in the control since those many years.

    I am still requesting the developers to look in to this and see if there is anything that can be done in this regard.

    ~Pragati

  • Posted 25 July 2018, 7:29 pm EST

    Hi,

    The ultimate reason for the unstable state of TDBGrid8 results because updating the same fields in the recordset and the grid generates a conflict for the checkboxed field. In grid6, changes to the recordset inside the BeforeColUpdate event were ignored and the buffered values in the grid overrode the changes to the recordset even if the grid column changes occurred first. This may be the reason you are coding for grid6 set the field/column value both in the grid and in the recordset. With grid8, the proper response is achieved by setting either the recordset values or the grid field values but not both.

    e.g:

    
    Select Case ColIndex
            Case EnumColumnaAplicacionAplicar ' Aplicar
                'tdbgrdAplicacion.Columns(EnumColumnaAplicacionVlrAAplicar).Value = 0
                recAdoAplicacion.Fields("valoraaplicar").Value = 0
    
                'tdbgrdAplicacion.Columns(EnumColumnaAplicacionVlrPPago).Value = 0
                recAdoAplicacion.Fields("valorprontopago").Value = 0
    End Select
    
    

    Only setting the recordset values OR only the grid Column values avoids the unstable state.

    The state becomes unstable when the buffered grid column values no longer match the field values of the recordset. When that occurs, the grid refetches the data, but this generates the conflict between the half applied boolean field/checkbox column as the recordset value is opposite that of the changing grid value.

    Therefore, grid 8 behavior is correct and the grid 6 behavior is not. This change is not unique to grid 8 but was also present in grid 7, with the change taking place more than 16 years ago.

    Another alternative for you is to set the boolean field/column value in the BeforeColUpdate event as well, but this will only work with the latest drop, build 381.

    http://prerelease.componentone.com/hotfixes/activex/TrueDBGrid8_8.0.20182.381.zip

    http://prerelease.componentone.com/hotfixes/activex/list8_8.0.20182.371.zip

    ~Pragati

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels