TDBXError with message 'Invalid Ordinal:1'.

Discussion of open issues, suggestions and bugs regarding usage of dbExpress drivers for SQL Server in Delphi and C++Builder
Post Reply
xalion
Posts: 124
Joined: Fri 20 May 2005 10:08

TDBXError with message 'Invalid Ordinal:1'.

Post by xalion » Thu 27 Jan 2011 07:06

Development Environment:
Embarcadero RAD Studio XE
mssql 2005
dbExpress driver for MS SQL Server 4.75.27

Code: Select all

function TService.acceptSaveIceOrders(Value: TJSONObject): TJSONObject;
var
  cmd: TDBXCommand;
  tr: TDBXTransaction;
  sqlstr: string;
  FID, SN: string;
  i:Integer;
begin
  if not Assigned(Value) then
    raise Exception.Create('Invalid message');
  Init;
  FID := CreateGuidString;
  tr := Connection.DBXConnection.BeginTransaction();
  try
    cmd := Connection.DBXConnection.CreateCommand;
    OrgSystem.getCorp(Value.Get('RELATIONID').JsonValue.Value);
    try
      sqlstr := '';
      sqlstr := sqlstr +
        'insert into enter(fid, fstate, fbillcode, fperiodcode, fsn, fdate, fcorpcode, fcorpname, ';
      sqlstr := sqlstr +
        'fperson1, fcustomercode, fcustomername, frelationid, fbscorderdate, forderstate, fnsccode, fnscname) values(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) ';
      cmd.Text := sqlstr;
      cmd.Prepare;//Unable to get parameters
      i:=cmd.Parameters.Count;//result:i=0
      cmd.Parameters[0].Value.SetString(FID);//This line generates an error:Invalid Ordinal:0
      cmd.Parameters[1].Value.SetString('10');
      cmd.Parameters[2].Value.SetString('504');
      cmd.Parameters[3].Value.SetString('2008-11');
......
The same code, when using interbase 2009+dbExpress driver for IB, there is no this error.
In fact, this problem is :Can't fecth parameters object by Prepare method of dbCommond.

AndreyZ

Post by AndreyZ » Fri 28 Jan 2011 08:44

Hello,

The point is that the logic of working of SQL Server differs from that of InterBase and it has its own specificity. Such behaviour is correct, you can check it with the standard dbExpress driver for SQL Server. To solve the problem you should create parameters manually in the following way:

Code: Select all

pm1 := TDBXParameter.Create;
pm1.DataType := TDBXDataTypes.WideStringType;
cmd.Parameters.AddParameter(pm1);

Post Reply