代码如下,table1的字段name为CHAR类型,bina为BINARY类型。请高手赐教!谢谢!        
Query.SQL.Text:='insert into table1 (name,bina) values (:p0,:p1)';
Query.Parameters[0].Value:='myname';
Query.Parameters[1].Value:=$FF;
Query.Prepared;
Query.ExecSQL;

解决方案 »

  1.   

    insert   into   table1   (name,bina)   values   ('name',0xff)
      

  2.   


    function ToHexString(const Buf; Size: Integer): string;
    const
      HexTables: PChar = '0123456789ABCDEF';
    var 
      I: Integer;
      S: PByte;
      P: PChar;
    begin
      SetLength(Result, Size * 2 + 2);
      S := @Buf;
      P := PChar(Result);
      P[0] := '0';
      P[1] := 'x';
      Inc(P, 2);
      
      for I := 0 to Size - 1 do
      begin
        P[0] := HexTables[S^ shr 4];
        P[1] := HexTables[S^ and $F];
        Inc(P, 2);
        Inc(S);
        P[0] 
      end; 
    end;var
      Buffer: array [0..20] of Byte;  Buffer[0] := $FF;
      Buffer[1] := $00;
      ...  Query.SQL.Text := Format('insert into table1 values(''%s'', %s);', ['myname', ToHexString(Buffer[0], sizeof(buffer))]);
      Query.ExecSQL;
      

  3.   

    Query.SQL.Text:= 'insert   into   table1   (name,bina)   values   (:p0,:p1); '; 
    加一个分号