代码为://提示牌
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
大家帮看看。谢谢 这两天就跟这个绕了……
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
大家帮看看。谢谢 这两天就跟这个绕了……
解决方案 »
- 请教一个查询问题
- 怎么得到小数的整数部分,去尾而不四舍五入
- 如何获取系统当前日期上午6点至后一天上午6点之间的数据?
- 公司换了一个域名,原来在服务器上的SQL Server的实例名,在我的机器上现在看不见了。
- 在select语句中使用变量
- 请问,如何同时查询两个表中的数据
- 今夜你会不会来::大力,一个比较复杂的报表统计??
- 服务器出了问题,请大侠帮忙
- ? 请求高手急救!-----VB ,DAO, 之SELECT 查询
- 在WHERE语句的条件中,如果有字段为TEXT类型(SQL SERVER),是不是不能作为条件查询,分数多多,等你拿!!!!
- 一道题.^^^^^^^^^^^^^^^^^^^^^^^^^^^
- 手工删除过期备份遇到的三个问题
但是关键的是MESSAGEBOX 显示的是0
这意味着 根本没有得到第一个查询应该得到的值
存在的编号纪录应该去做更新 而不是 插入。现在的情况就是他一直在做插入。
所以希望大家看看
select count(*) //查询符合条件的编号
into :n
from notes,pbjtnote
where notes.nid = :nid and
notes.typeid = :typeid and
notes.userid=:userid ;
写的哪有问题?现在返回的结果总是0
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) 这样都行呀。