Subject Re: [IBO] Posting a second record to a Dataset linked to a TIB_Grid
Author Helen Borrie
At 06:26 PM 4/10/2005 +0000, you wrote:
>Hi Helen,
>Now I remember my original problem that persists for weeks and was
>posted before.
>Take a look on my original question:
>
>I am using a TIB_Grid linked to a TIB_DataSource and a TIB_Query.
>I have this code at IB_QueryContaAfterInsert event:
>with IB_QueryConta do
>begin
>...
>FieldByName('cct_ciireg').AsString := Gl_ciireg_f;
>...
>end;
>Im this case, Gl_ciireg_f = '10010001'

If 1) the field 'cct_ciireg' is present in the SELECT statement

and

2) you have correct keylinks

an

3) the dataset's RequestLive property is set to True

then this assignment will work.

>For a new record, the user types values for other fields on the
>TIB_Grid. Field cct_ciireg is not visible on the grid, so user cannot
>change it.
>I checked that the code above actually executes.
>I watched FieldByName('cct_ciireg').AsString in 2 different places:
>at end of IB_QueryContaAfterInsert event and
>at end of IB_QueryContaBeforePost event
>In both places, the value is correct = '10010001'
>Although, when posting record, I got this ISC Error Message:
>ISC ERROR CODE: 335544347
>validation error for column CCT_CIIREG, value "***null***"
>
>Looking at TIB_Monitor, the real Insert statement doesn't have field
>cct_ciireg, but only fields that are on the TIB_Grid (cct_ciireg is
>one of the fields whose value is assigned on code, not on grid,
>because it is in the Query but not in the grid):


>These are the strings from TIB_Monitor:
>
>INSERT INTO CONTA
>( CCT_CONTA
>, CCT_TITULO
>, CCT_TIPO
>, CCT_CUSCOD
>, CCT_ORDEM
>, CCT_RATEIO)
>VALUES
>( ? /* CONTA.CCT_CONTA */
>, ? /* CONTA.CCT_TITULO */
>, ? /* CONTA.CCT_TIPO */
>, ? /* CONTA.CCT_CUSCOD */
>, ? /* CONTA.CCT_ORDEM */
>, ? /* CONTA.CCT_RATEIO */ )

OK, if CCT_CIIREG really is present in the dataset, then this InsertSQL was
not constructed by IBO.

>FIELDS = [ Version 1 SQLd 0 SQLn 30 ]
>----*/
>/*---
>[ 16/09/2005 07:02:11 ]
>EXECUTE STATEMENT
>TR_HANDLE = 14164468
>STMT_HANDLE = 14166400
>PARAMS = [ Version 1 SQLd 6 SQLn 6
>CONTA.CCT_CONTA = '110103018'
>CONTA.CCT_TITULO = 'teste'
>CONTA.CCT_TIPO = 'A'
>CONTA.CCT_CUSCOD = 'teste'
>CONTA.CCT_ORDEM = 0
>CONTA.CCT_RATEIO = 0 ]
>
>ERRCODE = 335544347
>----*/
>/*---
>[ 16/09/2005 07:02:11 ]
>INTERPRET BUFFER =
>
>ERRCODE = 60
>----*/
>/*---
>[ 16/09/2005 07:02:11 ]
>INTERPRET BUFFER = validation error for column CCT_CIIREG, value "***
>null ***"
>
>Submiting these questions on Forum before, somebody suggests to fill
>in the IB_Query Insert property (at end of BeforePost event) with the
>statement I want to submit to the server.

That's not correct advice for the problem as you describe it here.

If you intend to use the Insert method of the dataset, you need the
InsertSQL to be present before the SELECT statement is prepared. As I have
explained before, for a simple SELECT statement, IBO does this
automatically, as long as you have taken proper care with KeyLinks. If you
need to use custom SQL (which does not appear to be the case here)

Having a field's Visible property set to True does NOT prevent it being
assigned to or, more broadly, you are mistaken if you think that the
InsertSQL is constructed from the fields that are visible in the grid.

I want to see the exact SELECT statement that is used to get the
dataset. From there, I can show you what you need to do to make this
internal assignment. We are not talking about anything complicated. The
corrections I did to your online example are all you need to assign a value
to a hidden field.

Helen