偶今天用 ADOCommand.CommandText := 'SELECT * FROM :table',然后设置 Peremeter,却“SELECT语法错误”,后来改为字符串拼接,一切正常。然后又尝试“INSERT .... VALUES(:peremeter)”、“INSERT INTO :peremater ....”,均无法成功,唯一只有 “WHERE=:peremeter” 能成功。特上来问一下各位高手,Peremeter 是不是只能用在 WHERE 的内容?

解决方案 »

  1.   

    with ADOCommand1 do begin
      CommandText := 'INSERT INTO Talley ' +
        '(Counter) ' +
        'VALUES (:NewValueParam)';
      CommandType := cmdText;
      Parameters.ParamByName('NewValueParam').Value := 57;
      Execute
    end;
      

  2.   

    ADOCommand.CommandText := 'SELECT * FROM ' + TableNameString + '...' ;
      

  3.   

    to  jiezhi(西域浪子):我想把你的表名字也替代,
    with ADOCommand1 do begin
      CommandText := 'INSERT INTO :table ' +
        '(Counter) ' +
        'VALUES (:NewValueParam)';
      CommandType := cmdText;
      Parameters.ParamByName('NewValueParam').Value := 'Talley';
      Parameters.ParamByName('NewValueParam').Value := 57;
      Execute
    end;这样就执行不了!
      

  4.   

    with ADOCommand1 do begin
      CommandText := 'INSERT INTO :table ' +
        '(Counter) ' +
        'VALUES (:NewValueParam)';
      CommandType := cmdText;
      Parameters.ParamByName('table').DataType := ftString;
      Parameters.ParamByName('table').Value := 'Talley';
      Parameters.ParamByName('NewValueParam').Value := 57;
      Execute
    end;
      

  5.   

    const
      cmd: string ='select * from %s';
    begin
      ...
      adoCommand.CommandText := Format(cmd, [tablename]);
      ...
    end;