0

I am trying to insert data into a SQL Server database from TwinCat 2 program. When the trigger is activated, I am getting the following error: 262145

Error codes

racer_name : STRING(256);
racer_name := 'CS1';

FB_FormatStringC1_lap_db(
    sFormat:='INSERT INTO demo VALUES (%S, %D, %D)',
    arg1:= F_STRING(racer_name),
    arg2:= F_DWORD(C1_Lap_Minutes),
    arg3:= F_DWORD(C1_Lap_Seconds),
    bError=> ,
    nErrId=> ,
    sOut=>sInsertStringC1_lap_db );


FB_DBRecordInsertC1_lap_db(
    sNetID:= ,
    hDBID:=1 ,
    sInsertCmd:=sInsertStringC1_lap_db ,
    bExecute:=  dummy,
    tTimeout:=T#30s ,
    bBusy=> bBusyInsert,
    bError=> bErrInsert,
    nErrID=> nErridInsert,
    sSQLState=> );

Db design

The communication to the server is running, because i tried to import only integers and it's working without any problem.

Maybe I am not formatting the string variables properly?

Thanks in advance.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
ZhivkoPetkov
  • 33
  • 1
  • 5
  • For future reference, post the actual and complete error message - including the number, text, state, etc. within your post as text. Posting images is highly discouraged for many reasons. – SMor Sep 25 '20 at 11:21

1 Answers1

1

This is your query:

INSERT INTO demo VALUES (%S, %D, %D)

You are giving 3 columns for insert while your table has 4. Assuming that id is autogenerated, you can explictly not provide it by enumerating the target columns:

INSERT INTO demo (racer, minuteslap, secondslap) VALUES (%S, %D, %D)

This is one of the reasons why always enumerating the target columns in a insert statement is a best practice.

GMB
  • 216,147
  • 25
  • 84
  • 135