Page 1 of 1

TDBXError with message 'Invalid Ordinal:1'.

Posted: Thu 27 Jan 2011 07:06
by xalion
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.

Posted: Fri 28 Jan 2011 08:44
by AndreyZ
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);