BeforeColUpdate (Data type mismatch during update)

Posted by: juan.ome on 13 March 2018, 1:10 pm EST

  • Posted 13 March 2018, 1:10 pm 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
  • Replied 13 March 2018, 1:13 pm EST

    I forget.. it is on VB6
  • Marked as Answer

    Replied 14 March 2018, 3:13 am 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
  • Replied 9 April 2018, 12:21 pm 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.
  • Replied 10 April 2018, 6:46 am 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.
  • Replied 20 April 2018, 3:45 pm 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.
  • Replied 20 April 2018, 5:00 pm EST

  • Replied 24 April 2018, 5:25 am 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
  • Replied 24 April 2018, 12:08 pm 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
  • Replied 27 April 2018, 2:31 am 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
  • Replied 27 April 2018, 12:57 pm EST

    Finally! it's great...I'll be waiting your response!!!
  • Replied 30 April 2018, 12:36 am 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
  • Replied 3 May 2018, 9: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
  • Replied 4 May 2018, 12:39 pm 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.
  • Replied 7 May 2018, 5:44 am 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
  • Replied 28 May 2018, 10: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
  • Replied 29 May 2018, 5:29 am 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
  • Replied 26 July 2018, 4:29 am 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