代码为://提示牌
string ncomn
int n
select count(*)                         //查询符合条件的编号
into :n
from notes,pbjtnote
where notes.nid = :nid  and
      notes.typeid = :typeid and
      notes.userid=:userid ;
 messagebox("",n) 
if trim(w_main.mle_1.text)<>"" then         //是否为空
 ncomn=w_main.mle_1.text   if n=0 then                              //不为空,不存在 做插入
 INSERT INTO notes  
         ( typeid,   
           nid,   
           userid,   
           comn )  
  VALUES ( :typeid,   
           :nid,   
           :userid,   
           :ncomn )  ;
 else                                        //不为空,存在 做更新
  UPDATE notes  
     SET comn = :ncomn  
   WHERE ( notes.typeid = :typeid ) AND  
         ( notes.nid = :nid ) AND  
         ( notes.userid = :userid )   
           ;  end if
end if运行时 messagebox 显示为0 可我notes表里已经有对应的纪录同时报SQLSTATE = 23000  违反了 主键约束'PK_notes'。不能在对象'notes'中插入重复值notes 结构typeid   varchar  20 主键nid        int            4  主键     userid   varchar   20 主键comn    text   16
大家帮看看。谢谢 这两天就跟这个绕了……

解决方案 »

  1.   

    没错 这个看出来
    但是关键的是MESSAGEBOX 显示的是0
    这意味着 根本没有得到第一个查询应该得到的值
    存在的编号纪录应该去做更新 而不是 插入。现在的情况就是他一直在做插入。
    所以希望大家看看 
    select count(*)                        //查询符合条件的编号 
    into :n 
    from notes,pbjtnote 
    where notes.nid = :nid  and 
          notes.typeid = :typeid and 
          notes.userid=:userid ; 
    写的哪有问题?现在返回的结果总是0
      

  2.   

    搞定!select count(*)
    into :n
    from notes,pbjtnote
    where notes.nid = :nid  and
          notes.typeid = :typeid and
          notes.userid=:userid ;
     messagebox("",n) 仔细看了下,其实问题出在FROM 那我只用了notes 表 pbjtnote根本没有用,我删了就好了。改成:select count(*)
    into :n
    from notes
    where notes.nid = :nid  and
          notes.typeid = :typeid and
          notes.userid=:userid ;
     messagebox("",n) 这样都行呀。
      

  3.   

    4F的 不是sql 是什么呀 呵呵。