环境winXP,delphi 7, postsgresql 8.4, 已安装odbc for postgresql连接方式ado -> odbc -> postgresql
  con1.ConnectionString := 'Provider=MSDASQL.1;Extended Properties="DRIVER={PostgreSQL ODBC Driver(UNICODE)};DATABASE=DataBase1;'
                           + ' SERVER=127.0.0.1;PORT=5432;UID=postgres;PWD=123456; '
                            + ' ReadOnly=0;Protocol=7.4;FakeOidIndex=0;ShowOidColumn=0; '
                            + ' RowVersioning=0;ShowSystemTables=0;ConnSettings=;Fetch=100; '
                            + ' Socket=4096;UnknownSizes=0;MaxVarcharSize=254; '
                            + ' MaxLongVarcharSize=65536;Debug=0;CommLog=0;Optimizer=1;Ksqo=1; '
                            + ' UseDeclareFetch=0;TextAsLongVarchar=1;UnknownsAsLongVarchar=0; '
                            + ' BoolsAsChar=1;Parse=0;CancelAsFreeStmt=0; '
                            + ' ExtraSysTablePrefixes=dd_;LFConversion=1;UpdatableCursors=1; '
                            + ' DisallowPremature=0;TrueIsMinus1=0;BI=0;ByteaAsLongVarBinary=0; '
                            + ' UseServerSidePrepare=0"' ;
  qry1.Sql.Text := 'select id from table1';
   qry1.Active := True;
  qry1.Append;
  qry1.FieldValues['id'] :='1';//执行到这句报错Field 'id' cannot be modified
 

解决方案 »

  1.   

    qry1.Append;
    qry1.edit;
    qry1.FieldValues['id'] :='1';//执行到这句报错Field 'id' cannot be modified
      

  2.   

    id如果为主键,当然不能修改!访问pg,推荐zeoslib
      

  3.   

    跟主键没关系,其他字段都是这样。
    我知道有zeoslib,今天刚查到的,但如果能不改用,就不要改用别的控件。
      

  4.   

    qry1右键进入fields editor后检查一下字段是不是只读状态。
      

  5.   

    fields editor里是空的。不过手动把字段添加到fields editor里,这字段是只读的 ReadOnly=ture。改为false后这一步能通过了。但是post时报错
    “raised exception class EOleException with message '无法插入空行。行必须至少
    有一个列值集。'”
    qry1.Active := True;
      qry1.Append;
      qry1.FieldValues['id'] :='1';
      qry1.post; //'无法插入空行。行必须至少有一个列值集。'
      

  6.   

    不是自增的,不是主键,可为null
      

  7.   

    所有字段都不能修改?
    所有表都不能修改?是不是pgsql的访问限制表里对你这个ip、帐号做了限制?
      

  8.   

    用户是postgres  对所有表都有修改,创建,删除,查询的权限
      

  9.   

     qry2.SQL.Text := 'insert into table1 (id) values (1)';
     qry2.ExecSQL;
    执行没问题,有数据插入成功